[英]How to use Class getMethod with lombok @Data
我正在嘗試使用 lombok @Data 調用 Class getMethod() 方法來調用模型的 getter,但我遇到了 NoSuchMethod 異常。 下面是我的課:
模型類:
@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)
更好的解釋點擊這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.