[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:13:00 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 edited comment on CDI-455 at 8/28/14 5:12 AM:
------------------------------------------------------------------
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:
{code}
new TypeLiteral(ChocolateEater.class, argument.getClass()){}
{code}
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:
{code}
new TypeLiteral<ChocolateEater<? extends Chocolate>>(argument.getClass()){}
{code}
It is right?
was (Author: lucasvc):
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:
{code}
new TypeLiteral(ChocolateEater.class, argument.getClass()){}
{code}
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:
{code}
new TypeLiteral<ChocolateEater<? extends Chocolate>>(argument.getClass()){}
{code}
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
(v6.3.1#6329)
More information about the cdi-dev
mailing list