On 16/05/2009, at 9:27 AM, Mike Schrag wrote:

public WORequest createRequest( String method,
                              String aurl,
                              String anHttpVersion,
Map< String, ? extends List< String >> someHeaders,
                              NSData content,
                              Map< String, Object > someInfo )
{
Map< String, List< String >> correctHeaders = new HashMap< String, List< String > >();
        
        NSList<String> nslist = null;
        someHeaders.put( "foo", nslist ); // compile error
        correctHeaders.put( "foo", nslist ); // no problems

        NSMutableArray<String> array = null;
        someHeaders.put( "foo", array ); // compile error
        correctHeaders.put( "foo", array ); // no problems
        
}

You don't need extends for interfaces AFAIK.
Not sure what you're showing here, but you are correct that you don't need extends to control the value you put into the map. You need the extends to control what generic impls you can pass in as the PARAMETER to the method.

Ugh - yeah. Helps if I save the editor :-)

So if you're showing that a Map<String, List<String>> allows you to put a subtype of List as the value, I totally agree. The problem is that a Map<String, NSArray<String>> is NOT assignable to a Map<String, List<String>> -- this is the Integer vs Number problem*, and it's not a typesafe operation.

Right - lights are back on now. Cool.

* I keep this in my Stickies in like 24pt type, so every time I say "WTF CAN'T I DO THAT", i can run stickies and remind myself:

WHY IT'S ILLEGAL TO UPCAST GENERICS

Map<String, Integer> integers = new HashMap<String, Integer>();
Map<String, Number> numbers = integers; // illegal
numbers.put("str", Long.valueOf(1)); // and this is why

now a long is in integers


Generics are great mostly - but there are times when it's just downright annoying :-).

with regards,
--

Lachlan Deck

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to