根据Propertydescriptor判断属性是否有getsetg方法,Java.beans包下
package com.hdx.hkafka; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; public class PropertydescriptorTest { private String testName; public static void main(String[] args) { Class<?> clazz = PropertydescriptorTest.class; try { // 如果属性testName没有get和set方法此行抛出异常 Method not found: isTestName PropertyDescriptor propertydescriptor = new PropertyDescriptor("testName", clazz); // 获取个get方法 propertydescriptor.getReadMethod(); // 获取个set方法 propertydescriptor.getWriteMethod(); } catch (IntrospectionException e) { e.printStackTrace(); } } }
标签:Propertydescriptor,testName,propertydescriptor,getsetg,PropertyDescriptor,beans, From: https://www.cnblogs.com/hu0529/p/16951032.html