首页 > 解决方案 > 超类作为列表中的附加类型

问题描述

public abstract class class1 {
      int h;
    }

public class class2 extends class1{
      int y;
    }


import java.util.ArrayList;
import java.util.List;
class Main {
  public static void main(String[] args) {
    System.out.println("Hello world!");
    List<class1> test;
    test = new ArrayList<class2>();
  }
}

我收到以下错误错误:不兼容的类型:ArrayList 无法转换为 List

标签: java

解决方案


推荐阅读