You can no longer directly reference java.util.ArrayList if you've done the 2 things you've done:在作用域中使用静态嵌套类隐藏简单名称 ArrayList .使用嵌套在类 util 中,嵌套在嵌套类中的类 ArrayList 隐藏全限定名 java.util.ArrayList java .Hide the simple name ArrayList with a static nested class in scope.Hide the fully qualified name java.util.ArrayList with a class ArrayList nested within class util, nested within nested class java.您甚至无法拆分"导入,以尝试使用部分合格"的导入.You can't even "split" the import in an attempt to use a "partially qualified" import.import java.*;...// This doesn't work!new util.ArrayList<>();您可以 import java.*; ,但这毫无价值;没有直接在 java 包中定义任何类.You can import java.*;, but that is worthless; no classes are defined in the java package directly.但是,您可以间接引用类 java.util.ArrayList ,因为它不是 final .在类 Ideone 的范围之外,声明一个具有不同名称的子类.However, you can reference the class java.util.ArrayList indirectly because it's not final. Outside the scope of the class Ideone, declare a subclass with a different name.class AnArrayList<T> extends java.util.ArrayList<T> {}然后您可以在接口中引用该类和程序:Then you can refer to that class and program to the interface:List<Integer> al = new AnArrayList<>(); // won't print !! or Here 这篇关于当简单名称和完全限定名称发生冲突时如何引用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-26 16:40