dev@jsr311.java.net

Re: JSR311: TypeLiteral

From: Dhanji R. Prasanna <dhanji_at_gmail.com>
Date: Wed, 4 Jun 2008 20:14:24 +1000

On Wed, Jun 4, 2008 at 7:39 PM, Stephan Koops <Stephan.Koops_at_web.de> wrote:

> Hi Paul,
>
> sorry, I'm not sure if I understand what you want to say (I should use more
> English ...). Do you mean my idea is good or will not work?
>
> Stephan
>
> Paul Sandoz wrote:
>
>> Stephan Koops wrote:
>>
>>> Hi,
>>>
>>> what about a generic Response class?
>>> Let's stay at the given example:
>>> public List<Bean> getList() { ... }
>>> could become
>>> public Response<List<Bean>> getList() { ... }
>>
>>
In this example, it is not possible to determine the parameterized type of
the returned object via reflection due to type erasure. You *can* actually
do it by inspecting the method signature, but this is a somewhat unreliable
workaround.

In other words there is no way to distinguish an object of type
Response.class from Response<List<Bean>>.class (if the latter were valid
syntax). That's where super type-tokens and TypeLiteral can help.

Dhanji.