commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman" <ja...@carmanconsulting.com>
Subject Re: [all] Generics and Return Type?
Date Thu, 10 Apr 2008 01:45:08 GMT
Well, I figured out a way to have proxy determine the type of a method
when doing invocation recording.  It took me a while, but I got it.
The code is checked into the proxy 2.0 branch.  Now, I've got my
builders working for commons-expression, too! :)


On Wed, Apr 9, 2008 at 6:30 PM, Michael Heuer <heuermh@acm.org> wrote:
> On Wed, 9 Apr 2008, Antonio Petrelli wrote:
>
>  > 2008/4/9, James Carman <james@carmanconsulting.com>:
>  > > Does anyone have code that can take care of this situation:
>  > >
>  > >  List<String> strings = new ArrayList<String>();
>  > >
>  > >  Class returnType = getReturnType(strings.getClass(), "get", int.class);
>  > >
>  > >  I want the "returnType" to be java.lang.String.  Does anyone have code
>  > >  that would return that?  Is it possible?
>  >
>  > It's not possible:
>  > http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
>  >
>  > <snip>
>  > Generics are implemented by type erasure: generic type information is
>  > present only at compile time, after which it is erased by the
>  > compiler.
>  > </snip>
>
>  Right, you can get at the declared type(s) with e.g.
>
>
>  List<String> strings = new ArrayList<String>();
>  ParameterizedType parameterizedType = (ParameterizedType)
>   strings.getClass().getGenericSuperclass();
>  Type[] types = parameterizedType.getActualTypeArguments();
>  System.out.println(Arrays.asList(types));
>
>  [E]
>
>  static class StringList extends ArrayList<String> { }
>
>  List<String> strings = new StringList();
>  ParameterizedType parameterizedType = (ParameterizedType)
>   strings.getClass().getGenericSuperclass();
>  Type[] types = parameterizedType.getActualTypeArguments();
>  System.out.println(Arrays.asList(types));
>
>  [class java.lang.String]
>
>  but not the runtime type(s).
>
>    michael
>
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message