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

查看:626
本文介绍了在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天全站免登陆