Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the type of a bean property be null?

In the book "Thinking in Java" there is an example of how to get information for a bean via Reflection/Introspection.

BeanInfo bi = Introspector.getBeanInfo(Car.class, Object.class);
for (PropertyDescriptor d: bi.getPropertyDescriptors()) {
  Class<?> p = d.getPropertyType();
  if (p == null) continue;
  [...]
}

In line 4 of that sample above there is a check if the PropertyType is null. When and under what circumstances does that happen? Can you give an example?

like image 441
dertoni Avatar asked Aug 24 '11 06:08

dertoni


1 Answers

From the JavaDoc:

Returns null if the type is an indexed property that does not support non-indexed access.

So I guess if the property type is an indexed property(like an array) it will return null.

like image 135
Petar Minchev Avatar answered Sep 23 '22 03:09

Petar Minchev