Are there any technical reasons to "optimize imports" via your editor? Eclipse, Intellij IDEA, and NetBeans all have ways to optimize imports. I'm wondering if there are reasons other than consistency. Also, is there a more optimal way of importing? I've seen different standards that individuals and orginations have for optimizing imports. For example...
import java.util.Map;
import java.util.List;
import com.company.MyClassThatUsesMap;
If I understand right, in the above example the classloader will load the Map
and List
classes before MyClassThatUsesMap
. Will this add any benefit to the speed at which the code will run versus the example below?
import com.company.MyClassThatUsesMap;
import java.util.List;
import java.util.Map;
Does this even matter at all or does the compiler fix it altogether?
If I understand right, in the above example the classloader will load the Map and List classes before MyClassThatUsesMap.
You don't understand right. Imports have nothing to do with execution-time handling. They only affect how the compiler resolves short names (e.g. Map
) into fully-qualified class/method names.
The aim of "optimizing" imports is for readability - not execution-time performance.
See more on this question at Stackoverflow