如何使用 Class getMethod 和 lombok @Data
How to use Class getMethod with lombok @Data
我正在尝试使用 lombok @Data 调用 Class getMethod() 方法来调用模型的 getter,但我遇到了 NoSuchMethod 异常。以下是我的 classes:
型号class:
@Data
public class Claim {
private String customerName;
}
用法:
Claim.class.get("getCustomerName", String.class)
异常:
Method threw 'java.lang.NoSuchMethodException' exception.
您可以使用以下代码:
new PropertyDescriptor("customerName", claim.getClass()).getReadMethod().invoke(claim)
更好的解释click here
我正在尝试使用 lombok @Data 调用 Class getMethod() 方法来调用模型的 getter,但我遇到了 NoSuchMethod 异常。以下是我的 classes:
型号class:
@Data
public class Claim {
private String customerName;
}
用法:
Claim.class.get("getCustomerName", String.class)
异常:
Method threw 'java.lang.NoSuchMethodException' exception.
您可以使用以下代码:
new PropertyDescriptor("customerName", claim.getClass()).getReadMethod().invoke(claim)
更好的解释click here