You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by Sean Owen <sr...@gmail.com> on 2010/05/31 19:04:23 UTC

Minor: TypeToken anonymous classes?

While wandering through the code I saw this construction:

    Type vectorType = new TypeToken<Vector>() {}.getType();

from reading the GSON source, it seems this is really just a long way of saying:

    Type vectorType = Vector.class;

am I missing anything? would be nice to not construct a new anonymous
class in these 5 instances or so.
But it's minor.

Re: Minor: TypeToken anonymous classes?

Posted by Benson Margulies <bi...@gmail.com>.
The metaphor is used to deal with complex issues in generic types.
Using it for a non-generic type like Vector seems, indeed, odd.

On Mon, May 31, 2010 at 1:04 PM, Sean Owen <sr...@gmail.com> wrote:
> While wandering through the code I saw this construction:
>
>    Type vectorType = new TypeToken<Vector>() {}.getType();
>
> from reading the GSON source, it seems this is really just a long way of saying:
>
>    Type vectorType = Vector.class;
>
> am I missing anything? would be nice to not construct a new anonymous
> class in these 5 instances or so.
> But it's minor.
>

Re: Minor: TypeToken anonymous classes?

Posted by Ted Dunning <te...@gmail.com>.
Yeah... this isn't real obvious.

But the problem is type erasure.

See here for a discussion:
http://code.google.com/p/google-gson/issues/detail?id=45

On Mon, May 31, 2010 at 10:04 AM, Sean Owen <sr...@gmail.com> wrote:

> While wandering through the code I saw this construction:
>
>    Type vectorType = new TypeToken<Vector>() {}.getType();
>
> from reading the GSON source, it seems this is really just a long way of
> saying:
>
>    Type vectorType = Vector.class;
>
> am I missing anything? would be nice to not construct a new anonymous
> class in these 5 instances or so.
> But it's minor.
>