[英]How to obtain JavaBean informations at runtime with new API (Java 9)?
我開發了一個庫 ( JAXX ) 來使用 Swing 小部件的 JavaBean 信息生成 Swing java 文件,我正在嘗試將其遷移到 Java > 9(請參閱問題)。
使用新的 JavaBean API 不再起作用,因為我使用運行時反射從 bean 獲取信息(請參閱JAXXIntrospector 類)。
private static BeanInfo getExplicitBeanInfo(ClassDescriptor classDescriptor) {
try {
Class<?> beanClass = Class.forName(classDescriptor.getName(), true, classDescriptor.getClassLoader()); // see if there is a class by that name in this package
Method findExplicitBeanInfo = Introspector.class.getDeclaredMethod("findExplicitBeanInfo", Class.class);
findExplicitBeanInfo.setAccessible(true);
return (BeanInfo) findExplicitBeanInfo.invoke(null, beanClass);
} catch (ClassNotFoundException | NoClassDefFoundError e) {
return null; // happens for uncompiled classes
} catch (NoSuchMethodException e) {
throw new RuntimeException("Error: could not find method 'findExplicitBeanInfo' in java.beans.Introspector. You are most likely running a version of Java against which JAXX has not been tested.");
} catch (InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
我試圖找到如何使用 Jigsaw 現在獲取這些信息,但找不到任何地方可以使用新的 API 來做到這一點。
我現在如何獲取這些運行時信息?
謝謝。
使用公共 API ( Introspector.getBeanInfo ) 解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.