Best way of invoking getter by reflection

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-04-14T15:14:54Z Indexed on 2010/04/14 15:23 UTC
Read the original article Hit count: 131

Filed under:
|
|

Hello,

I need to get the value of a field with a specific annotation, So with reflection I am able to get this Field Object. The problem is that this field will be always private though I know in advance it will always have a getter method. I know that I can use setAccesible(true) and get its value (when there is no PermissionManager), though I prefer to invoke its getter method.

I know that I could look for the method by looking for "get+fieldName" (though I know for example for boolean fields are sometimes named as "is+fieldName").

I wonder if there is a better way to invoke this getter (many frameworks use getters/setters to access the attributes so maybe they do in another way).

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection