Java 8 interface default method doesn't seem to declare property

后端 未结 3 1593
感情败类
感情败类 2020-12-14 10:17

In my application I run into a problem that when a getter in a class is defaulted in an interface only (Java 8 feature), there is no Java Beans property as a result. I.e. f

3条回答
  •  余生分开走
    2020-12-14 10:49

    A quick work-around:

    try {
        return PropertyUtils.getProperty(bean, property);
    }
    catch (NoSuchMethodException e) {
        String getMethod = "get" + property.substring(0, 1).toUpperCase() + property.substring(1);
        return MethodUtils.invokeMethod(bean, getMethod, new Object[]{});
    }
    

提交回复
热议问题