On 4 May 2012 14:45, Adriano B. Godinho <adri...@godinho.eng.br> wrote:
> You can instantiate your singleton instance in a static method:
>
> class C{
>
>     private static C mInstance = null;
>
>     public static C getInstance() throws YourException {
>            if (mInstance == null )  {
>                  mInstance = new C(); //it throws YourException
>             }
>
>            return mInstance;
>     }
>
> }


...which changes the original code from eager initialisation to lazy
initialisation (not a bad thing per se and optimisation is some
circumstances), but it remains not thread safe.


-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to