[英]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.