문제

I recently tried out AndroidAnnotations in Android. It has many interesting options and I like the way it reduces the boilerplate code.

However recently I came across the singleton scope for custom classes. I noticed that AndroidAnnotations does not restrict me from creating a new instance. For example CustomClassA obj = new CustomClassA();, even if the scope of CustomClassA is singleton.

As far as I know this should be restricted as per singleton pattern. I would like to have a solution to overcome this problem.

도움이 되었습니까?

해결책

AndroidAnnotations never change original code.

So it's up to the developer to make the constructor protected (or friendly) on the original class. It can't be private because generated class extends of the original one (so it has to be visible for this one). And the constructor is private on the generated class :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top