Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: getter/setter methods

How are a bean's getter methods invoked and set in various frameworks? is it only through reflections?

like image 930
Rnet Avatar asked Nov 05 '22 01:11

Rnet


1 Answers

Yes, most frameworks use reflections for that, with assumed requirement that you must use a proper getter / setter naming convention (getXXX and setXXX, or isXXX and setXXX for boolean property).

Performance may be an issue, but unless you benchmark your application and find reflections to be a major bottleneck, I would advise against premature optimization, and use reflections as the simplest solution. With that said, you may want to look at this article on replacing reflections with code generation:

http://www.ibm.com/developerworks/java/library/j-dyn0610/

like image 119
Robert Kovačević Avatar answered Nov 09 '22 13:11

Robert Kovačević