Hello Dishi,
Compiler generates error because you cannot widen and then box..
Actually what i believe is short is Autoboxed to Short but that Short type is not subclass of Integer,
so compiler says it cant find the appropriate method...
as it is Treeset. So, before inserting any new object (in this case number) it will compare with the previous object and then will insert.
The previous object is of Integer type and we are inserting short type which will ultimately autobox to Short. Comparison is ok. but
at the time of insertion Short into generic type of Integer will not allow as Integer and Short are are siblings under wrapper class and can't be casted to each-other.
Hello Prakash Mahto,
Actually it does not matter whether you use TreeSet or not..
variable number is correctly autoboxed to Short but
all wrapper classes are peers to one another so the compiler complains.
The modified code still gives the same error...
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss