开发者

Java: getter/setter methods

开发者 https://www.devze.com 2023-02-14 19:02 出处:网络
开发者_运维知识库How are a bean\'s getter methods invoked and set in various frameworks? is it only through reflections?Yes, most frameworks use reflections for that, with assumed requirement that you

开发者_运维知识库How are a bean's getter methods invoked and set in various frameworks? is it only through reflections?


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消