简体   繁体   中英

How to obtain JavaBean informations at runtime with new API (Java 9)?

I develop a library ( JAXX ) to generate Swing java file using JavaBean information of Swing widgets, that I am trying to migrate to Java > 9 ( See issue ).

Using new JavaBean API does not work any longer, since I was using runtime reflection to get information from beans (See JAXXIntrospector class ).

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);
    }
}

I try to find how to get now thoses information using Jigsaw but could not find anywhere to to do this with the new API.

How can I get those runtime information now ?

Thanks.

使用公共 API ( Introspector.getBeanInfo ) 解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM