> No prefix "m" is necessary, although for some reason many > people do that, and underscores are not conventional. Use > camel case, as 'mInstance' (if you must use the wart), or just > 'instance'.
I do disagree m_instance means private, just a c++ old fart convention anyway I never use public vars indeed rarely I prefer having inlined setter or/and getter especially if I need synchronization or a copy instead of holding a weak pointer or holding a shared pointer ref. > Really? Catching 'Throwable'? That is not very wise. we are toasted if it's happening let's crash later 8-) > Also, doing that initialization in a static initializer, it is redundant to > check I do like redundant code it makes it obvious > final yep I don't like this redondant word it makes my code ugly 8-) just digging into java crap, since a couple of week (I am forced) I just implement the thinnest layer I can, I not intend spending my life coding in java, too ugly, too slow, too assisted, hate garbage collection and JIT ( at least if you use it only on reasonable set of instructions... ) On Fri, May 4, 2012 at 2:03 PM, Lew <[email protected]> wrote: > Kristopher Micinski wrote: >> >> 0xcafefeed wrote: >> > public class TheClass extends Guigui >> > { >> > ... >> > /*#! Singleton */ >> > static >> > { >> > if (m_instance == null) { > > > Please follow the Java naming conventions. > > No prefix "m" is necessary, although for some reason many > people do that, and underscores are not conventional. Use > camel case, as 'mInstance' (if you must use the wart), or just > 'instance'. > >> >> > try { >> > m_instance = new TheClass(); >> > } >> > catch (Throwable e) { > > > Really? Catching 'Throwable'? That is not very wise. > >> >> > throw new >> > RuntimeException(e.getMessage()); > > > What if it already was a runtime exception? > > What if it was an 'Error' or top-level 'Throwable'? You have downgraded the > error to a runtime exception. > > Why do you initialize the runtime exception with the message and not the > 'Throwable' itself? > >> >> > } >> > } >> > } >> > ... >> > } >> > >> > started java [sic] since two weeks >> >> Impressive! Except that..., that doesn't really have to do with the >> issue that is being discussed here. >> > > Also, doing that initialization in a static initializer, it is redundant to > check > if the variable is null. It's effectively the same as a one-line > initializer: > > Except that with the one-liner you can make the variable 'final' and > avoid threading issues. > > private static final Singleton instance = new Singleton(); > > What do folks think that lazy initialization will buy them? > > -- > Lew > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

