私が持っているBeanクラスのPropertyDescriptorを作成しようとしています。私は電話していますjava.beans.PropertyDescriptor(String、Class)の動作が混乱しています
new PropertyDescriptor(myProperty, myClass)
"isMyProperty"というメソッドが存在しないという例外があります。 は、コードにビットを覗く -
/**
* Constructs a PropertyDescriptor for a property that follows
* the standard Java convention by having getFoo and setFoo
* accessor methods. Thus if the argument name is "fred", it will
* assume that the writer method is "setFred" and the reader method
* is "getFred" (or "isFred" for a boolean property). Note that the
* property name should start with a lower case character, which will
* be capitalized in the method names.
*
* @param propertyName The programmatic name of the property.
* @param beanClass The Class object for the target bean. For
* example sun.beans.OurButton.class.
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
public PropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
this(propertyName, beanClass,
"is" + capitalize(propertyName),
"set" + capitalize(propertyName));
}
ドキュメントは、それが「getFred」を探しますと言うが、それは常に"is" + capitalize(property)
を使用しています!これはJavaバージョン1.6.0_31です
考えですか?
'myProperty'はブール値のプロパティですか? – srkavin
これは本当にバグのようです。私の説明では、 'PropertyDescriptor'は通常、直接インスタンス化されるのではなく、' Introspector'と 'BeanInfo'を通って実行されます。それでも、これは公開APIです。 –
@srjavin:ブール値かどうかはどこでチェックされますか?いいえ、この場合はそうではありません。だからこそ私は混乱して、「そうした方法はありません」という意味です。マイプロパティ。 –