我剛剛注意到java.beans.Introspector getBeanInfo沒有獲取任何超級接口的屬性。例如:java.beans.Introspector getBeanInfo不能獲取任何超級接口的屬性
public interface Person {
String getName();
}
public interface Employee extends Person {
int getSalary();
}
對僱員的反思只會產生薪水,即使名稱是從Person繼承的。
這是爲什麼?我寧願不用反射來獲得所有的獲得者。
我試過了,它沒有工作。我的解決方案是通過調用類的getInterfaces()和getSuperclass()來反省超類和父接口。 – 2008-10-09 04:59:43
你只想要屬性?您可以從BeanInfo獲取屬性描述符,我相信它包含了所有屬性,包括來自超類的屬性。 – MetroidFan2002 2008-10-25 05:28:32