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)
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.
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.
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?