Rnet
Rnet

Reputation: 5040

Java: getter/setter methods

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

Upvotes: 5

Views: 1478

Answers (1)

Robert Kovačević
Robert Kovačević

Reputation: 1408

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/

Upvotes: 2

Related Questions