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

后端 未结 1 1758
天命终不由人
天命终不由人 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>>
    
    if (parameterType instancof ParameterizedType) {
        final Type nextDown // List>
            = ((ParameterizedType) parameterType).getActualTypeArguments();
    }
    

    And keep repeating until it is not a ParameterizedType.

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