我想为我有的bean类创建一个PropertyDescriptor。我打电话混淆java.beans.PropertyDescriptor的行为(字符串,类)
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 2012-04-24 17:56:18
这真的看起来像一个错误。我的解释是'PropertyDescriptor'通常不是直接实例化的,而是通过'Introspector'和'BeanInfo'实现的。不过,这是公共API。 – 2012-04-24 18:54:36
@srjavin:它甚至在哪里检查它是否是布尔值?不,在这种情况下它不是 - 这就是为什么我很困惑,我得到“没有这样的方法isMyProperty” – 2012-04-24 19:21:02