ankit
ankit

Reputation: 2845

How to use Class getMethod with lombok @Data

I am trying to call Class getMethod() method with lombok @Data to call getter of model but i got NoSuchMethod exception. Below are my classes:

Model class:

@Data
public class Claim {
    private String customerName;
}

usage:

Claim.class.get("getCustomerName", String.class)

Exception:

Method threw 'java.lang.NoSuchMethodException' exception.

Upvotes: 1

Views: 989

Answers (1)

AKA
AKA

Reputation: 638

You can use below code:

new PropertyDescriptor("customerName", claim.getClass()).getReadMethod().invoke(claim)

for better explaination click here

Upvotes: 3

Related Questions