Generic as method return type

前端 未结 1 1586
闹比i
闹比i 2021-01-16 22:52

I have looked around on StackOverflow to find the answer for the problem I am facing. I came across many good answers but still it doesn\'t answer my question.

Get t

相关标签:
1条回答
  • 2021-01-16 23:07
    Bar<Foo> bar = new Bar<Foo>();
    Method mRead = bar.getClass().getMethod( "getObject", null );
    TypeToken<Bar<Foo>> tt = new TypeToken<Test.Bar<Foo>>() {};
    Invokable<Bar<Foo>, Object> inv = tt.method( mRead );
    System.out.println( inv.getReturnType() ); // Test$Foo
    

    Maybe this is what you are searching for. TypeToken and Invokable are from Google Guava.

    €: Fixed the code with respect to the comment of @PaulBellora

    0 讨论(0)
提交回复
热议问题