Question

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.

Était-ce utile?

La solution

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 :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top