在Java中更改Import的名称,或导入两个具有相同名称的类

在Java中更改Import的名称,或导入两个具有相同名称的类

问题描述:

在Python中,您可以执行以下操作:

In Python you can do a:

from a import b as c

你如何用Java做这件事,因为我有两个冲突的进口。

How would you do this in Java, as I have two imports that are clashing.

Java中没有导入别名机制。你不能导入两个具有相同名称的类,并使用两个不合格的类。

There is no import aliasing mechanism in Java. You cannot import two classes with the same name and use both of them unqualified.

导入一个类并使用另一个类的完全限定名,即

Import one class and use the fully qualified name for the other one, i.e.

import com.text.Formatter;

private Formatter textFormatter;
private com.json.Formatter jsonFormatter;