Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么可能是ParameteredType的实例?_Java_Generics_Reflection - Fatal编程技术网

Java 什么可能是ParameteredType的实例?

Java 什么可能是ParameteredType的实例?,java,generics,reflection,Java,Generics,Reflection,阅读了接口文档后,我认为ParameterizedType实例的示例可以是任何参数化类型,例如我的代码中的col: public class a0 { public static void main(String[] args) { Collection<String> col = new ArrayList<String>(); col.add("a"); col.add("b"); co

阅读了接口文档后,我认为ParameterizedType实例的示例可以是任何参数化类型,例如我的代码中的
col

  public class a0 {

     public static void main(String[] args) {

        Collection<String> col = new ArrayList<String>();
        col.add("a");
        col.add("b");
        col.add("c");

        assert col instanceof ParameterizedType; // line No. 10
     }
  }
因此,什么可能是ParameteredType的实例

我想知道这一点,因为我试图理解一个更伟大的程序,其中有这样一个片段:

public static void printType(Type type) {
...
if (type instanceof ParameterizedType) {
... }
}

但我不知道
if
语句中的条件何时为真。

a
parameteredType
是表示参数化类型的反射类型。参数化类型本身不是该类的实例

类似地,实例用于表示特定类型的类成员字段。这并不意味着这样一个字段将是
field
的实例

参数化类型的示例如下所示:

Type[] genericInterfaces = col.getClass().getGenericInterfaces();
Type type = genericInterfaces[0];

assert type instanceof ParameterizedType;
Type[] genericInterfaces = col.getClass().getGenericInterfaces();
Type type = genericInterfaces[0];

assert type instanceof ParameterizedType;