On 3 May 2012 15:50, blake <[email protected]> wrote: > I'd say that the guy at devahead observed some behavior and lept to > some weird conclusions. > > ClassLoaders are just what they sound like. There can be two > different instances of a class object (right: not instances of the > class, instances of the class object) in two different class loaders. > The states of those two instance are unrelated and can be quite > different.
Blake, Good point! I would like to point out aditional peculiarity: Class loaders are organised in parent - children hierarchies (trees) with the boot classloader at the root. It is an important contract placed upon ClassLoader and one that is possible to break. Breaking this contract makes it possible to have two objects created from the same class file (i.e. implementing the same Class) but each class loaded by a different classloader. Now if at least one of these classloaders did not delegate the loading to its parent, it is posible to have object1.class != obejct2.class evalueate to TRUE. You are also mentioning singleton across different executions. There is also a case of singleton across serialize -> deserialize cycle. When the singleton happens to implement Serializeable, then it is possible to have more than 1 of them within the same JVM, but there are tricks... http://stackoverflow.com/questions/70689/efficient-way-to-implement-singleton-pattern-in-java Marry that with Android app/thread/activity lifecycles, and it is easy to come to wrong conclusions based on not exhaustive observations. Daniel > > The whole concept of a "singleton" requires definition. The singleton > on your computer is clearly not the same as the one on mine. A > singleton in the instance of a single application you ran 10 months > ago is probably not the same as the one in the instance you are > running right now. It's true, the "singletons" created using class > members in classes loaded by different class loaders are different. > > Blake Meike > Marakana > > The second edition of Programming Android is now on line! > http://shop.oreilly.com/product/0636920023005.do > > -- > 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 -- 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 [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

