Jeet Jain

Ranch Hand
+ Follow
since Sep 01, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jeet Jain

wow! thanks so much. I finally got the rules even though I'm confused about the reason behind the rules. But its fine for now. I have my OCJP exam tomorrow. Any tips? Anything about formats and all?
I'm sorry it does give a compiler error. So there's where my problem lies. It gives an error at compile time but number format gives at runtime.

One more doubt related to this was that why does Collections.sort() on a List<StringBuilder> give exception for natural and total ordering when at compile time itself it can see that StringBuilder is not a subtype of Comparable<? super StringBuilder>?

Signature for sort is:
<E extends Comparable<? super E>> void sort(List<E> list)
And another example:



Why can't the compiler itself determine that Sets are not Lists? Why does it give a runtime exception?
But thats exactly my problem. The format method() you specified (same as in API) above takes 3 parameters but my format() calls with 1 parameter. And in the API it gives both versions of format() methods. So the one with 1 parameter (format(double) or format(long)) should be called, right? Not the one with 3 parameters.
ohhhh thank you so much:) got it finally
You mean that at compile time set(Number) of SupC is called but after erasure compiler chooses to call set(Integer), i.e set(Object), instead? And that gives an error?
But it does not compile even if I put Feline or BarnCat instead of Animal at 14. But if I put any interface at 14. instead of Animal it compiles. I'm confused
I am very confused about when actual parameters are checked with formal parameters. When I saw the API it gives the above 2 versions of format() not one with Object as parameter.

But what I dont get is why when I pass str.concat(5); it gives compiler error and when i say NumberFormat.getNumberInstance.format(str); it compiles.

Please Help!!!
no I said line 14. if(r instanceof Animal) System.out.print("5 "); How can this compile?
oh but i thought the signature for format() was format(double d) and format(long l) ???
If I replace Animal with any other class like String or some class I defined like Wheel it doesn't compile.
Doesn't the instanceof operator not compile if is checking 2 completely unrelated types? Then why does line 14 compile? Robot and Animal are unrelated.

But remember you meant that the compiler sees generic and only JVM sees the erasure done before runtime. Then why does compiler complain about the erasures of set(Object) being the same? It doesnt see erasure right?
Also, how come the 1st time the compiler allowed (3) and gave error at (4) but when the error at (4) was cured by changing N to M it gave error at (3)? Why didnt it give an error the 1st time?