Studying the exercise that follows, I couldn't understand why LINE B and LINE C does not compile.
I'm getting very difficulty at questions that involves generics such this kind of question.
Could anybody help me with this?
Exercise from OCP Java SE 6 Programmer Practice Exams (Bert Bates & Katht Sierra)
Assessment Test 2: Question 11.
The method needs to return a Carpet of V, or a Carpet of something that inherits V; What is V will be decided when an instance of Carpet is instantiated. And it is not clear if B or C fulfills the IS-A V test.
Adolfo Eloy wrote:
I'm getting confusing because if V extends B, should not the compiler knows that V can be anything that extends B (IS-A B)?
Yes. The compiler knows that V IS-A B.... but the compiler also knows that B may not be IS-A V. Since B may not be IS-A V, there is no guarantee that Carpet<B> IS-A Carpet<? extends V>.