Is there some disadvantage to having statements such as import android.view.* instead of just importing the objects I actually use from the view package? Will it make my compiled android application larger in size if I use the *? If yes, then what is best practice for deciding whether to import the whole package with * or just single objects ? Thanks
Is there some disadvantage to having statements such as import android.view.* instead of just
Share
In their book Core Java Volume 1, the authors state that
The only time that you need to worry about packages is when you have a name conflict. For example, both the java.util and java.sql packages have a Date class. Now suppose you write a program that imports both packages.
*import java.sql.** and
*import java.util.**
If you try to use the Date class now, you will get a compile time error. You’ll have to use fully qualified name if you want to use them both.
The only benefit of the import statements is convenience. It is not analogous to the #include directives in C. In the book The Java Programmin Language (It has James Gosling as one of its authors), the authors state the following,
What I have inferred from the books The Java Language Specification (By Bill Joy, James Gosling et. al), and the one I mentioned above is that the import statements with the wild-cards are called Type-Import-on-Demand Declaration. This tells the compiler that if it finds names that it doesn’t know about, it should look at package given by the import-on-demand statement to see if it has a member by that name.