Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

same class name, different package

 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Palak Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic