Tell the difficulties that i am difficult.
Seetharaman Venkatasamy wrote:what the compiler is saying at line number 07? Foo[] and Foo are descendants in hierarchy
Tell the difficulties that i am difficult.
Seetharaman Venkatasamy wrote:Foo[] is a container *which holds* Foo objects. think in this way : you put mangos in a bag, but mango is not a bag and vice-versa.
Tell the difficulties that i am difficult.
saloni jhanwar wrote:
Seetharaman Venkatasamy wrote:Foo[] is a container *which holds* Foo objects. think in this way : you put mangos in a bag, but mango is not a bag and vice-versa.
Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas, so i think it might be possible here same as autoboxing like stuff.
=-- Anything less than immortality is a complete waste of time --=
saloni jhanwar wrote:Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
S.R Paul wrote:
saloni jhanwar wrote:
Seetharaman Venkatasamy wrote:Foo[] is a container *which holds* Foo objects. think in this way : you put mangos in a bag, but mango is not a bag and vice-versa.
Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas, so i think it might be possible here same as autoboxing like stuff.
Mmm, na.
Mango bag(Foo array) is a BAG(array) but Mango(Foo) is Mango(still Foo).
Therefore, a Bag cannot be an instance of a Mango.
Tell the difficulties that i am difficult.
Anayonkar Shivalkar wrote:
saloni jhanwar wrote:Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas
Similarly, when you access an element of the array, it would satisfy IS-A foo condition. But as long as you try to test bag instanceof mango, it will always return false.
Tell the difficulties that i am difficult.
Henry Wong wrote:Please QuoteYourSources.
Henry
Tell the difficulties that i am difficult.
saloni jhanwar wrote:It is other thing that there is no such automatic facility to open bag and compare each object and then again close bag like autoboxing type stuff.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
I know what is a mango and bag ,no cheap jokes here.So keep silence.
=-- Anything less than immortality is a complete waste of time --=
Anayonkar Shivalkar wrote:
saloni jhanwar wrote:It is other thing that there is no such automatic facility to open bag and compare each object and then again close bag like autoboxing type stuff.
Ah... now I got what you were saying. Yes, there's no such facility. But I guess there's a reason for it - consider an array of Object - which contains a String, an Integer, a Cat, a Dog and so on. Even if there is such autoboxing facility, how would dog instanceof array would work? I mean should it perform instanceof test with first member, second member, or any other? And on what basis?
Its just my thought though...
Tell the difficulties that i am difficult.
saloni jhanwar wrote:There is no monopoly that bag will have only mangoes, it can have bananas too.
Seetharaman Venkatasamy wrote:
saloni jhanwar wrote:There is no monopoly that bag will have only mangoes, it can have bananas too.
no. if it is a (Object[])Object bag then it can hold mangos , banana etc. but If it is a Foo[](Mango bag) , then only Mangos are allowed otherwise you will end up with ArrayStoreException
Tell the difficulties that i am difficult.
saloni jhanwar wrote:
Yes I know mango bag will allow only mangoes so any autoboxing type feature can open this bag and can check each mango using instanceof and again close it that was my idea that's it.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
S.R Paul wrote:into an array, if inheritance involved
Tell the difficulties that i am difficult.
Tell the difficulties that i am difficult.
saloni jhanwar wrote:
Anayonkar Shivalkar wrote:
saloni jhanwar wrote:Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas
Similarly, when you access an element of the array, it would satisfy IS-A foo condition. But as long as you try to test bag instanceof mango, it will always return false.
As i already said i know bag is not instanceof mango directly but it holds mangoes indirectly not bananas, when instanceof work for standalone object test then theoretically it will not wrong to test array of class objects that's it .It is other thing that there is no such automatic facility to open bag and compare each object and then again close bag like autoboxing type stuff.
Henry Wong wrote:
saloni jhanwar wrote:
Anayonkar Shivalkar wrote:
saloni jhanwar wrote:Yes ,but when you will open this bag, you'll definitely find mangoes in it not bananas
Similarly, when you access an element of the array, it would satisfy IS-A foo condition. But as long as you try to test bag instanceof mango, it will always return false.
As i already said i know bag is not instanceof mango directly but it holds mangoes indirectly not bananas, when instanceof work for standalone object test then theoretically it will not wrong to test array of class objects that's it .It is other thing that there is no such automatic facility to open bag and compare each object and then again close bag like autoboxing type stuff.
Not to beat a dead horse, but I can't imagine how a mechanism can be done. Unlike wrapper objects, which wrap a single value, array objects (and collection objects) can hold more than one element. There isn't a way to manually box and/or unbox that will always work, hence, I can't imagine how Java can do it in an "auto"mated way.
Henry
Tell the difficulties that i am difficult.
saloni jhanwar wrote:
Henry Wong wrote:
Not to beat a dead horse, but I can't imagine how a mechanism can be done. Unlike wrapper objects, which wrap a single value, array objects (and collection objects) can hold more than one element. There isn't a way to manually box and/or unbox that will always work, hence, I can't imagine how Java can do it in an "auto"mated way.
Henry
I believe one day that java version will come to prove me
Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
Mohamed Sanaulla wrote:
saloni jhanwar wrote:
Henry Wong wrote:
Not to beat a dead horse, but I can't imagine how a mechanism can be done. Unlike wrapper objects, which wrap a single value, array objects (and collection objects) can hold more than one element. There isn't a way to manually box and/or unbox that will always work, hence, I can't imagine how Java can do it in an "auto"mated way.
Henry
I believe one day that java version will come to prove me
If there is no real need for the feature, it will would never be considered to be added to the language.
Tell the difficulties that i am difficult.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |