在Java中更改Import的名称,或导入两个同名的类 [英] Change Name of Import in Java, or import two classes with the same name

查看:128
本文介绍了在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;

这篇关于在Java中更改Import的名称,或导入两个同名的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆