Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.beans.Introspector getBeanInfo does not pickup any superinterface's properties

I just noticed that java.beans.Introspector getBeanInfo does not pickup any superinterface's properties. Example:

public interface Person {
    String getName();
}
public interface Employee extends Person {
    int getSalary();
}

Introspecting on Employee only yields salary even though name is inherited from Person.

Why is this? I would rather not have to use reflection to get all the getters.

like image 529
Steve Kuo Avatar asked Oct 08 '08 21:10

Steve Kuo


3 Answers

This issue is covered in Sun bug java.beans.Introspector doesn't work for interfaces

like image 195
Phil Avatar answered Nov 12 '22 12:11

Phil


The Java VM does not support this out of the box as Phil wrote. I also needed this and implemented a helper class as part of Diergo Utils 1.5.

like image 33
Arne Burmeister Avatar answered Nov 12 '22 12:11

Arne Burmeister


Try using

public static BeanInfo getBeanInfo(Class<?> beanClass, Introspector.USE_ALL_BEANINFO);

and see if this yields the result you're looking for.

like image 1
MetroidFan2002 Avatar answered Nov 12 '22 10:11

MetroidFan2002