开发者

Upsides and downsides of importing specifically and importing overally

开发者 https://www.devze.com 2023-03-14 12:43 出处:网络
I noticed that people prefer importing javax.swing.JFrame instead of javax.swing.* , importing java.math.BigInteger instead of ja开发者_开发知识库va.math.* , etc... Is there any downside of importing

I noticed that people prefer importing javax.swing.JFrame instead of javax.swing.* , importing java.math.BigInteger instead of ja开发者_开发知识库va.math.* , etc... Is there any downside of importing the whole package instead of importing specifically or is there any upsides importing specifically?


Well one point I've have read against package imports is that they cause problems if the classes are added to the package later causing ambiguity . Like jdk 1.1 contained just one List class in java.awt package , jdk1.2 introduced another List class in java.util package .


Usually single class imports are preferred because they make it easy to figure which class is imported. And with modern IDE it's very easy. So it's often considered a good style. There is no difference between package and single class imports.


None whatsoever. The import statement is a compiler directive and has no effect on the compiled code. You can have a further read here and here (you can probably find better sources, but that was a 1 minute Google exercise).


This also seems like a duplicate of this question.


You might notice a slower compilation time when you do wildcard import, this is because all classes would be loaded by the compiler at compile time. But it has no effect to the runtime performance.

0

精彩评论

暂无评论...
验证码 换一张
取 消