内容へ移動
Cat Paw Software
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
トレース:
java:introspection
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== Introspection ====== 動的にJavaBeanのGetter、Setterを呼び出すには、IntrospectorとBeanInfoを使ってアクセサメソッドオブジェクトを取得します。 <code java> SomeBean someBean = new SomeBean(); PrintStream ps = System.out; try { BeanInfo beanInfo = Introspector.getBeanInfo(someBean.getClass()); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd: pds) { String propertyName = pd.getName(); Method method = pd.getReadMethod(); if (method == null) { continue; } Object propertyValue = method.invoke(someBean, new Object[0]); ps.print(propertyName); ps.print("="); ps.println(propertyValue); } } catch (IntrospectionException e) { e.printStackTrace(ps); } catch (IllegalArgumentException e) { e.printStackTrace(ps); } catch (IllegalAccessException e) { e.printStackTrace(ps); } catch (InvocationTargetException e) { e.printStackTrace(ps); } </code>
java/introspection.txt
· 最終更新:
2010/12/13 07:11
by
127.0.0.1
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ