I know most variable names will work with \"is\", such as isBlue()
, but is \"has\" also a valid prefix, like hasProperty()
?
Jon Skeet noted that according to the specification it is not valid. Also, canX
, shouldX
, and the likes are not valid. Which is rather unfortunate. Here is a way to check whether a given property has a valid getter:
BeanInfo info = Introspector.getBeanInfo(Item.class);
Item itm = new Item();
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
System.out.println(pd.getName() + " : " + pd.getReadMethod());
}
The class Item
should be a javabean with a foo property, and a getter. If the read method is null
, it means there is no valid getter defined according to the javabeans spec.