dev@jsr311.java.net

Re: JSR311: GenericEntity can only support one parameter

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 20 Aug 2008 17:25:26 -0400

On Aug 20, 2008, at 3:59 PM, Bill Burke wrote:

> Why does GenericEntity only support one generic parameter? i.e.
> List<String>? Why are we narrowing the superclass generic type to a
> ParameterizedType and getting the first parameterized value?

The code is getting the type of the GenericEntity which only has one
generic parameter. E.g. for GenericEntity<Map<String,Integer>> the
type is Map<String, Integer>. It isn't getting the type of the Map,
you have to do that yourself from the Type returned by getType().

> There's no reason we couldn't have a Map as an entity object.
>
You can. With the existing code the following works fine:

     public void testMapOfStringInteger() {
         System.out.println("testMapOfStringInteger");
         Map<String,Integer> map = new HashMap<String,Integer>();
         GenericEntity<Map<String,Integer>> mapOfString = new
GenericEntity<Map<String,Integer>>(map) {};
         Class<?> rawType = mapOfString.getRawType();
         assertEquals(rawType, HashMap.class);
         Type type = mapOfString.getType();
         assertTrue(type instanceof ParameterizedType);
         ParameterizedType pType = (ParameterizedType)type;
         Type typeArgs[] = pType.getActualTypeArguments();
         assertEquals(2, typeArgs.length);
         assertTrue(typeArgs[0] instanceof Class<?>);
         Class<?> typeArgType = (Class<?>)typeArgs[0];
         assertEquals(typeArgType, String.class);
         assertTrue(typeArgs[1] instanceof Class<?>);
         typeArgType = (Class<?>)typeArgs[1];
         assertEquals(typeArgType, Integer.class);
     }

> The constructor should really be:
>
> protected GenericEntity(T entity)
> {
> if (entity == null)
> {
> throw new IllegalArgumentException("The entity must not be
> null");
> }
> this.entity = entity;
> this.type = getClass().getGenericSuperclass();
> this.rawType = entity.getClass();
> }
>
I don't think so, then the Type would be GenericEntity<Whatever> not
Whatever which is what we want.

> Logged issue here:
>
> https://jsr311.dev.java.net/issues/show_bug.cgi?id=47
>

Can I close it with no action given the above.

Marc.

>
>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: dev-help_at_jsr311.dev.java.net
>

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