Discussion:
Problems getting TypeLiteral to resolve type parameters
John Gardiner Myers
2017-08-11 23:31:55 UTC
Permalink
I am having no end of problems trying to figure out how to get TypeLiteral
to resolve a type parameter.

I am creating a custom binder with method

public <T> AnnotatedAuditLoggerBinder bind(Class<T> recordClass)

which wants to create a binding for AuditLogger<T> with T resolved to
recordClass.

I have a Provider<AuditLogger<T>> which I can construct for appropriate
Class<T>.

I cannot figure out how to get a suitably resolved TypeLiteral with which
to call getReturnType().
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/2487b74a-6da7-40de-88b9-f9ab8f64f764%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tavian Barnes
2017-08-14 14:19:54 UTC
Permalink
Post by John Gardiner Myers
I am having no end of problems trying to figure out how to get TypeLiteral
to resolve a type parameter.
I am creating a custom binder with method
public <T> AnnotatedAuditLoggerBinder bind(Class<T> recordClass)
which wants to create a binding for AuditLogger<T> with T resolved to
recordClass.
I have a Provider<AuditLogger<T>> which I can construct for appropriate
Class<T>.
I cannot figure out how to get a suitably resolved TypeLiteral with which
to call getReturnType().
Something like

(TypeLiteral<AuditLogger<T>>)TypeLiteral.get(Types.newParameterizedType(
AuditLogger.class, recordClass))
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/7afe115b-e007-49bd-aa8a-8c1555e28a0b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...