I've raised this problem before, got help, thought I understood the help I got and closed it.
However I realise I'm still confused by it.
Question 58 is as follows :-
Which can be inserted, independently at line 4, for the code to compile?
a. return e;
b. return e.getE();
c. return e2;
d. return e2.getE();
e. return new Hose().getE();
f. Compilaton failes regardless of which return is inserted.
The correct answer is f. as the doStuff() method is static. I don't have a problem with that.
However the book says that if doStuff() was non-static, a. and d. would be correct.
I can understand c. being wrong as then a Hose<E> is being returned instead of an E.
However I don't understand why b. is also wrong.
Henry Wong explained that the e is something that IS-A Hose and getE() will return something that IS-A Hose, but they may not be IS-A each other.
I understand the principle that two objects which both directly sub-class another class are not IS-A each other.
However I don't understand how that could occur in this situation.
Can someone give an example of what could give rise to this situation if option b. DID compile?
ALSO, if I may, changing line 1 to
enables the code to compile with line b.
However I don't know what "Hose <E extends Hose<E>>" really means - what does it mean?
And I am not able to instantiate a Hose object of this type - what is the correct syntax?