Javadoc for getPropertyType method of the PropertyDescriptor class:
The result may be "null" if it is an indexed property that does not support unindexed access.
Indexed properties are those that are supported by an array of values. In addition to standard JavaBean access methods, indexed properties can also have methods for getting / setting individual elements in an array by specifying an index. Therefore, a JavaBean can have indexed getters and setters:
public PropertyElement getPropertyName(int index) public void setPropertyName(int index, PropertyElement element)
optional standard receiver and setter for non-indexed access:
public PropertyElement[] getPropertyName() public void setPropertyName(PropertyElement element[])
Moving on to the Javadoc description, if you omit unindexed accessors, you can get a null return value for the property descriptor property type.
So, if you have the following sort of JavaBean, you can get a null return value:
class ExampleBean { ExampleBean() { this.elements = new String[10]; } private String[] elements; // standard getters and setters for non-indexed access. Comment the lines in the double curly brackets, to have getPropertyType return null. // {{ public String[] getElements() { return elements; } public void setElements(String[] elements) { this.elements = elements; } // }} // indexed getters and setters public String getElements(int index) { return this.elements[index]; } public void setElements(int index, String[] elements) { this.elements[index] = elements; } }
Please note that although you can only implement indexed property accessors, this is not recommended because standard accessors are used to read and write values if you use the getReadMethod and getWriteMethod methods.
Vineet reynolds
source share