How to get all types of the inner structures of a nested type?

后端 未结 1 1772
天命终不由人
天命终不由人 2021-01-28 02:58

I have a function bellow,

public void park( List>> l){ System.out.println(\"park\"); }

and when I tried

相关标签:
1条回答
  • 2021-01-28 03:27

    You can get this information through the ParameterizedType interface.

    For example:

    final Type parameterType = method.getGenericParameterTypes()[0]; // List<List<List<Integer>>>
    
    if (parameterType instancof ParameterizedType) {
        final Type nextDown // List<List<Integer>>
            = ((ParameterizedType) parameterType).getActualTypeArguments();
    }
    

    And keep repeating until it is not a ParameterizedType.

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