• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing - What is the point of 'classname.*' on non-static imports?  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So as I continue to gear up for the associate exam, one thing has bothered me with imports. I can't figure out why someone would ever use the following:

import PackageName.SomeClassName.*; (I am capitalizing purely for readability here, not based on accepted standards)

What would that actually allow me to do? I can't make an instance of the class (SomeClassName), nor can I figure out a way to use it's variables and methods b/c it's my understanding that non-static import variables/methods are only available via an instance of a class?

I know that if I did this instead, I could make an instance and use all the variables/methods via that instance:
import PackageName.SomeClassName;

Thanks for any help clearing up the confusion of why someone would want to the ".*" version versus importing the whole class? And what using the ".*" version actually allows you to access/do?
 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That does actually exist. It would allow you to import inner/nested classes of that class. You are hardly going to use that very frequently.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!