Generic Lazy initialize state solution using CGLIB
I have meanwhile made my solution in my previous post more generic using annotations (@StateInitializeMethod for the init method(s) and @RequiresState for methods which require the state to have been initialized) , and it can be used like this:
public class DemoClass { private int x; @RequiresState public int getX(){ return x; } @RequiresState public int getNumber(){ return x; } @StateInitializeMethod public void init(){ x =10; } public static void main(String[] args) { DemoClass instance = LazyInitalizeStateClass.getInstance(DemoClass.class); System.out.printf("x=%d\n",instance.getX()); } } |
The source code for the LazyInitalizeStateClass is available here: LazyDemo.tar
About this entry
You’re currently reading “ Generic Lazy initialize state solution using CGLIB ,” an entry on Sirius ICT
- Published:
- 6.23.09 / 4pm
- Category:
- Blog, Course- & PresentationWare
No comments
Jump to comment form | comments rss [?] | trackback uri [?]