实体类实例.getClass().getMethod("get" + "Age").invoke(实体类实例));
相当于
实体类实例.getAge();
该逻辑应用于不同场景。(本人收藏用)
通过实体类实例的getClass().getMethod(get+Age).invoke()方法,可以动态调用getAge()函数,实现对对象属性的访问,这种方式是基于Java反射机制。此逻辑适用于需要动态调用getter方法的不同场景。
实体类实例.getClass().getMethod("get" + "Age").invoke(实体类实例));
相当于
实体类实例.getAge();
该逻辑应用于不同场景。(本人收藏用)
2283
1万+
2181

被折叠的 条评论
为什么被折叠?