[cdi-dev] [JBoss JIRA] (CDI-455) Allow building of TypeLiteral's with dynamic types

Lucas Ventura Carro (JIRA) issues at jboss.org
Thu Aug 28 05:12:59 EDT 2014

    [ https://issues.jboss.org/browse/CDI-455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12996376#comment-12996376 ] 

Lucas Ventura Carro commented on CDI-455:

As [~jharting] told in the mailing list, type safety cannot be guaranteed. But this will happen if the {{TypeLiteral}} has the raw and parameterized types as arguments. But IMHO the usual use case is that raw type is fixed, but not the parameterized types of it.
In example, following [this of guice|http://luisfsgoncalves.wordpress.com/2010/09/08/generic-bindings-with-guice/], CDI {{TypeLiteral}} could be built as:
new TypeLiteral(ChocolateEater.class, argument.getClass()){}
And efectively, type safety would be lost. But if we know that we will have an static {{ChocolateEater}} but a dynamic {{Chocolate}} parameter, we can have type safety and the {{TypeLiteral}} could be built as:
new TypeLiteral<ChocolateEater<? extends Chocolate>>(argument.getClass()){}

I'm I correct?

> Allow building of TypeLiteral's with dynamic types
> --------------------------------------------------
>                 Key: CDI-455
>                 URL: https://issues.jboss.org/browse/CDI-455
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>            Reporter: Lucas Ventura Carro
> It could be useful the building of {{TypeLiteral}}'s, but using dynamic types. This way, the types can be indicated at runtime and not in compile. This functionality is "doable" as it is done at [Guice|https://github.com/google/guice], a similar injection framework, and as [this post shows|http://luisfsgoncalves.wordpress.com/2010/09/08/generic-bindings-with-guice/].

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list