What's the message you get?
Kumar Jaya wrote:I think you get it???
Embla Tingeling wrote:
Kumar Jaya wrote:
his means the downcast is typesafe in practice
No it is not, you can assign the instance to a singleton<String> reference and set variable then assign it to a singleton<Integer> and try to use it as an Int. At runtime the JVM can't tell whether the singleton instance contains a String or Int, because of this, it can't check the cast and throw a ClassCastException before you try to do something really silly...![]()
OCJP 6 (93%)
Embla Tingeling wrote:
Kumar Jaya wrote:
his means the downcast is typesafe in practice
No it is not, you can assign the instance to a singleton<String> reference and set variable then assign it to a singleton<Integer> and try to use it as an Int. At runtime the JVM can't tell whether the singleton instance contains a String or Int, because of this, it can't check the cast and throw a ClassCastException before you try to do something really silly...![]()
OCJP 6 (93%)
Embla Tingeling wrote:
his means the downcast is typesafe in practice
OCJP 6 (93%)
OCJP 6 (93%)
Lorand Komaromi wrote:
Embla Tingeling wrote:
his means the downcast is typesafe in practice
No it is not,
Campbell Ritchie wrote:Maybe you can use
private static final Singleton<T> instance;
instead. Using final will reduce the risk of your instantiating it twice by mistake.
Vivek Singh wrote:
Campbell Ritchie wrote:Maybe you can use
private static final Singleton<T> instance;
instead. Using final will reduce the risk of your instantiating it twice by mistake.
This is the best and smartest way to introduce Singleton.
Campbell Ritchie wrote:private static final Singleton<T> instance;
Well, first of all your declaration inside the class will have to be
view plaincopy to clipboardprint?
1. private static T instance;
private static T instance;
That's because your singleton object is supposed to be of type T, right?
Kumar Jaya wrote:I am trying from all the posts from Paul, Embla to find out a way..
Embla Tingeling wrote:
I still claim that the downcast in my solution is typesafe but I'll change my mind if Lorand Komaromi manages to come up with a counterexample showing it is not.
OCJP 6 (93%)
Kumar Jaya wrote:and have some doubts lurking in my mind.
Steve
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |