简体   繁体   English

在Eclipse中导入“导入”-Java

[英]Import “imports” in eclipse - Java

I have several java files in a package and all of them have the same import blocks eg : 我在一个包中有几个Java文件,它们都有相同的导入块,例如:

package org.ezim.core;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;

import org.ezim.core.Ezim;
import org.ezim.core.EzimDtxSemantics;
import org.ezim.core.EzimLogger;
import org.ezim.ui.EzimFileOut;
import org.ezim.ui.EzimMain;

It looks awful having the same batches of code in each file and i want to refactor it. 在每个文件中具有相同批次的代码看起来很糟糕,我想对其进行重构。

I was wondering if its possible to put all these imports in a single java file then use a single line in all the other java files to call them. 我想知道是否有可能将所有这些导入放在单个java文件中,然后在所有其他java文件中使用一行来调用它们。

Its like the extend function for classes (for variables) , but i want one for the imports. 就像类的扩展函数(用于变量)一样,但是我想要一个用于导入。

Thanks 谢谢

No. That isn't possible. 不,那是不可能的。 What is possible is not using imports at all, instead you can use fully qualified class names like 可能根本不使用导入,而是可以使用完全限定的类名,例如

org.ezim.core.Ezim ezim = new org.ezim.core.Ezim(); // <-- not import needed.

您始终可以使用*符号从一个包中导入多个类,但是要注意名称冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM