| Author |
Name Ambiguities
|
Enkita mody
Ranch Hand
Joined: Aug 06, 2012
Posts: 333
|
|
Name Ambiguities
If a member in one package shares its name with a member in another package and both packages are imported, you must refer to each member by its qualified name. For example, the graphics package defined a class named Rectangle. The java.awt package also contains a Rectangle class. If both graphics and java.awt have been imported, the following is ambiguous.
Rectangle rect;
In such a situation, you have to use the member's fully qualified name to indicate exactly which Rectangle class you want. For example,
graphics.Rectangle rect;
If there is a such circumstance then it doesn't make any sense to import them when ultimately we have to use fully qualified name.
|
OCA7
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
ankita modi. wrote:If there is a such circumstance then it doesn't make any sense to import them when ultimately we have to use fully qualified name.
In those circumstances, no, there's, no need to import them. It's relatively rare, though.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
For me it's java.util.Date and java.sql.Date. Though that pretty much gets resolved by using JPA.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
In the old days, java.awt.List and java.util.List also could cause conflicts. They still can if you import java.awt.* and java.util.*.
java.io.FileFilter and javax.swing.filechooser.FileFilter also can cause conflicts, especially since both share approximately the same purpose. I'm still annoyed that javax.swing.filechooser.FileFilter does not implement java.io.FileFilter because it already has its sole method.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Ivan Jozsef Balazs
Ranch Hand
Joined: May 22, 2012
Posts: 380
|
|
This reduces the dependency across different packages.
But you can derive a class from it having only the constructors and the "implements" clause.
|
 |
Enkita mody
Ranch Hand
Joined: Aug 06, 2012
Posts: 333
|
|
I didn't ever try to access MAX_VALUE in program then Why there is compile error ?
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
|
With those import statements, you're telling the compiler "I want to be able to refer to both Integer.MAX_VALUE and Long.MAX_VALUE as simply MAX_VALUE. The compiler's smart enough to realise that doesn't make sense, even without you trying to use them.
|
 |
 |
|
|
subject: Name Ambiguities
|
|
|