aspose file tools*
The moose likes Beginning Java and the fly likes same class name, different package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "same class name, different package" Watch "same class name, different package" New topic
Author

same class name, different package

Palak Agarwal
Greenhorn

Joined: Nov 02, 2011
Posts: 21
hi all,
I am facing the similar kind of issue. Below are the two different packages which I am trying to import. Both of them contains the class with same name.
it does not allow the code to get compiled and says "already defined in single-type import".

import com.lowagie.text.Document;
import com.sforce.soap.enterprise.sobject.Document;

How to resolve this issue ?

Thanks
Palak
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Palak Agarwal wrote:hi all,
I am facing the similar kind of issue. Below are the two different packages which I am trying to import. Both of them contains the class with same name.
it does not allow the code to get compiled and says "already defined in single-type import".

import com.lowagie.text.Document;
import com.sforce.soap.enterprise.sobject.Document;

How to resolve this issue ?

Thanks
Palak


You may import only one of the types. The other must be referred to by its fully-qualified name.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

I have split these last two posts off their original...There is no need to re-open a 9+ year old thread. feel free to create a new thread for your new questions - we have plenty of room!

In regards to your question...

Remember that all an "import" does is say "i really don't want to have to type the fully qualified name each time, so when I say X, I really mean 'fully.qualified.name.of.class.X'"

So by importing two classes in different packages with the same name, you are basically saying:


import com.lowagie.text.Document; // When I type "Document", I mean the one called com.lowagie.text.Document
import com.sforce.soap.enterprise.sobject.Document; //When I type "Document", I mean the one called com.sforce.soap.enterprise.sobject.Document

So how is the compiler supposed to know which you REALLY want? It can't. So, your solution, as Dennis points out, is to import one, and then use the full name for the other each time.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Palak Agarwal
Greenhorn

Joined: Nov 02, 2011
Posts: 21
hi thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: same class name, different package
 
Similar Threads
XSL/XML structure clashing
CORBA exception while executing ejb call
Strange behaviour of MDB and EJB
Question about clone a Hashtable
Applet-to-Applet, ClassCastException