I noticed that people prefer importing javax.swing.JFrame
instead of javax.swing.*
, importing java.math.BigInteger
instead of java.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With