简体   繁体   中英

Import “imports” in eclipse - Java

I have several java files in a package and all of them have the same import blocks eg :

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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