Can Guava’s TypeToken get the specific type of a generic field?

前端 未结 1 1227
暗喜
暗喜 2021-01-27 11:17

I wrote a parser for a file format called ASN.1 that uses Guice’s TypeLiteral.getFieldType(Field) to convert generic fields into specific Java types so I can constr

1条回答
  •  终归单人心
    2021-01-27 11:51

    From my head, not verified

    Type t = B.class.getDeclaredField("b").getGenericType();
    Class p = TypeToken.of(t).resolve(
            /* T */  A.getTypeParameters()[0]).getRawType();
    // p should be String.class
    

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