This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am a little confused as to what the second argument in Hose.doStuff (E e, Hose<E> e2) will accept.
In the example provided in this thread, Hose is instantiated as:
Hose <Foo> h = new Hose <Foo>();
which makes me think that the second argument in doStuff will only take a Hose<Foo> as an argument, but we seem to be passing it a Foo<Bar>.
If someone could explain this, it would be most helpful.
Joined: Dec 25, 2011
Okay - I think I get it now. e2's InnerE we know will be of the same type specified in the return, but we can not say the same about e's InnerE. This is due to the fact that we know the generic type E specified in the return type is also the same generic type specified in Hose<E>.