Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

single type import...??

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does it mean when one says,
"a single-type import will take precedence over an import-on-demand"
moreover
what do we mean by
single type import??
import-om demand??
what's the difference b/w above two??
Thanks in advance
Lusha
[This message has been edited by lusha tak (edited May 27, 2001).]
 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the import statement, you can import the exact
thing that you need and no more (the exact class name for example).
You can also refer to whole class and have the system import
what is needed in the class when it needs it. When you use the class in you program, it will look in the import <...>.* and locate what you need.
Hope this clears it up.
 
Scott Appleton
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"a single-type import will take precedence over an import-on-demand"

I'm not sure what is meant by "take precedence". You can have both types of imports in a single source file. Anyone able to explain the meaning of this statement?
 
Junilu Lacar
Bartender
Pie
Posts: 7250
44
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Appleton:
I'm not sure what is meant by "take precedence". You can have both types of imports in a single source file. Anyone able to explain the meaning of this statement?

Probably means that if you had a Foo class in two different packages, e.g. package1 and package2, then
import package1.Foo;
import package2.*;
Foo f = new Foo(); // pulls in package1.Foo, not package2.Foo

Junilu
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
When determining which class to use, the compiler follows a set of 'lookup' rules. First it checks the source file for the type, then it looks for a single-type import that matches the classname, then it checks the import-on-demand packages. It stops checking when it finds a type that matches the required one; if no class is found or the declarations are ambiguous, you get a compile error
See JLS �6.5.5 Meaning of Type Names
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited May 29, 2001).]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic