• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Curly Generics Question - Update
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Curly Generics Question - Update


  • Subject: Re: Curly Generics Question - Update
  • From: Lachlan Deck <email@hidden>
  • Date: Sat, 16 May 2009 09:59:13 +1000


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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Curly Generics Question - Update
      • From: Chuck Hill <email@hidden>
References: 
 >Curly Generics Question (From: Andrew Lindesay <email@hidden>)
 >Re: Curly Generics Question - Update (From: Andrew Lindesay <email@hidden>)
 >Re: Curly Generics Question - Update (From: Jim Kinsey <email@hidden>)
 >Re: Curly Generics Question - Update (From: Mike Schrag <email@hidden>)
 >Re: Curly Generics Question - Update (From: Lachlan Deck <email@hidden>)
 >Re: Curly Generics Question - Update (From: Mike Schrag <email@hidden>)

  • Prev by Date: Re: [OT] JD-Eclipse plug-in available for Mac OS X
  • Next by Date: Re: Curly Generics Question - Update
  • Previous by thread: Re: Curly Generics Question - Update
  • Next by thread: Re: Curly Generics Question - Update
  • Index(es):
    • Date
    • Thread