Re: JAX-RS: generics: vs

  • From: Marc Hadley <Marc.Hadley@...>
  • To: users@...
  • Subject: Re: JAX-RS: generics: <String,Object> vs <String,?>
  • Date: Wed, 16 Jul 2008 08:36:02 -0400
  • Mailing-list: contact users-help@...; run by ezmlm

On Jul 16, 2008, at 2:56 AM, Manger, James H wrote:

One method in UriBuilder is
  build(Map<String,Object> values);

I think it should be
  build(Map<String,?> values);
so callers can pass, say, a Map<String,String> to the method – which is the most likely type they will be using.

build(…) only reads the Map so it should be fine with <String,?>.


I am not totally confident about this, because I am not totally confident about generics and I seem to be able to pass a Map<String,String> to the Jersey (0.9) implementation of build()!

Either works. Strings are Objects so Map<String, String> is assignable to Map<String, Object>. You can think of Map<String, Object> as equivalent to Map<String, ? extends Object>, the compiler treats them the same IIRC. I prefer the Map<String, Object> since a user can actually instantiate one - you can't, e.g. write Map<String, ?> m = new HashMap<String, ?>().

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.






JAX-RS: generics: <String,Object> vs <String,?>

Manger, James H 07/16/2008

Re: JAX-RS: generics: <String,Object> vs <String,?>

Marc Hadley 07/16/2008

RE: JAX-RS: generics: <String,Object> vs <String,?>

Manger, James H 07/16/2008

Re: JAX-RS: generics: <String,Object> vs <String,?>

Marc Hadley 07/17/2008

RE: JAX-RS: generics: <String,Object> vs <String,?>

Manger, James H 07/17/2008

Re: JAX-RS: generics: <String,Object> vs <String,?>

Stephan Koops 07/17/2008

RE: JAX-RS: generics: <String,Object> vs <String,?>

Manger, James H 07/18/2008

Re: JAX-RS: generics: <String,Object> vs <String,?>

Marc Hadley 07/19/2008
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150226.965aeb8)
 
 
Close
loading
Please Confirm
Close