Problems getting TypeLiteral to resolve type parameters

37 views
Skip to first unread message

John Gardiner Myers

unread,
Aug 11, 2017, 7:31:55 PM8/11/17
to google-guice
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().

Tavian Barnes

unread,
Aug 14, 2017, 10:19:54 AM8/14/17
to google-guice
Something like

(TypeLiteral<AuditLogger<T>>)TypeLiteral.get(Types.newParameterizedType(AuditLogger.class, recordClass))

Reply all
Reply to author
Forward
0 new messages