简体   繁体   中英

Generating Getters/Setters with AspectJ

I want to write an aspect that will generate getters/setters for the fields of a class where it is being used.

I am a beginner to AspectJ, can someone point me in the right direction? A sample would be nice.

Check out Spring Roo which generates getters and setters by generating AspectJ ITDs.

Not the most elegant thing but it gets the job done with out the runtime cost of other things like lambok.

What you are looking for is Project Lombok . It generates getters/setters and various other handy methods. It integrates with Eclipse so technically non-existing accessors are visible.

(not fully sure but...) I'm affraid that aspect programming can add behaviour to classes, not interface. If you could generate getters/setters in runtime... anyway you coudn't call them in your code because they wouldn't exist yet. You'd have a compile-time error.

Maybe you could use some IDE source generator. As in Eclipse: Source menu -> generate getters/setters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM