Generic as method return type

前端 未结 1 1587
闹比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 bar = new Bar();
    Method mRead = bar.getClass().getMethod( "getObject", null );
    TypeToken> tt = new TypeToken>() {};
    Invokable, 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)
提交回复
热议问题