File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Name Ambiguities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Name Ambiguities" Watch "Name Ambiguities" New topic
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: 4372
    
    8

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: 61095
    
  66

For me it's java.util.Date and java.sql.Date. Though that pretty much gets resolved by using JPA.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
Rob Spoor wrote:I'm still annoyed that javax.swing.filechooser.FileFilter does not implement java.io.FileFilter because it already has its sole method.


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: 4372
    
    8

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Name Ambiguities