Re: Java type-casting -- Q1
Lew wrote:
Daniel Pitts wrote:
One general rule that I've found is:
When you only read from a structure, declare it <? super Type>.
When you only write to a structure, declare it <? extends Type>.
When you read/write to a structure, declare it <Type>.
Brian Goetz, in "Going Wild with Generics, Part 2: The get-put
principle"
<http://www.ibm.com/developerworks/java/library/j-jtp07018.html>
says the opposite:
The get-put principle, as stated in Naftalin and Wadler's fine book on generics,
/Java Generics and Collections/ (see Resources), says:
Use an extends wildcard when you only get values out of a structure,
use a super wildcard when you only put values into a structure,
and don't use a wildcard when you do both.
I think I'll believe Messrs. Goetz, Naftalin and Wadler on this one.
--
Lew
Indeed, That is what I *meant* to say. It was an unfortunate reversal of
my intent :-)
Read: <? extends Type>
Write: <? super Typer>
Both: <Type>
I apologize for leading anyone astray.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>