Can you please tell me why this program is throwing ClassCastExcep
But if i implement comparator why does it print 1 2 3 since i added in 3 1 2 fashion, it should have printed in the same fashion
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Originally posted by Manju:
Here we are directly trying to display the elements returned by next() method. I think you know that when we try to display the object, then its toString() method is called. So here we are actually calling the toString() mothod of "Object" class which is overridden in the Car(subclass). Polymorphism!
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Originally posted by mukki pandey:
A TreeSet either requires you to use a Comparator, or have Comparable objects in the set. Since you are *not* using a Comparator, it is assuming that the objects are Comparable. Since your objects are not, this will generate a class cast exception.
Comparable objects in the sense.....i mean whats wrong with baove code
list.add(c1); this is calling construtor with interger values
can anyone please explain
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
That means if the toString() method is overridden, then even if dont cast it's ok and it will run
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
I love a good mentalist. And so does this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|