• Post Reply Bookmark Topic Watch Topic
  • New Topic

Import duplicate class name .. different package  RSS feed

 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am modifying an existing method which now needs to import an existing class. The class I need to import is a duplicate name of another package already being imported.

Example.

Currently

import package1.methodA;

Now I need to

import package2.methodA;

I've tried googling package alias, import alias etc etc.
I'm sure there must be a way to do this, if someone can point me in the proper direction I'd appreciate it.

Thanks.

Marc
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

You can't import both classes; you have to refer to one of them by its fully-qualified name. i.e.,

import package1.methodA;

...

methodA x = new methodA(); // This refers to package1.methodA
package2.methodA = new package2.methodA();
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

I'm not sure what you're trying to do. You can't import methods. Instead you import classes. So if it's a name collision of methods in different classes it's in fact not a problem at all. If you want to import two CLASSES with the same name instead you will have to use the full qualified class name for one of them in your code.

Marco
[ May 23, 2008: Message edited by: Marco Ehrentreich ]
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest:

Perfect! Thank you so much.
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Name ambiguities are discussed in the java tutorial here
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marco Ehrentreich:
You can't import methods.

Yes you can - if they're static. That's what the entire static import is for. For example:
import static java.lang.Math.abs;
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, my answer was not very precise. It was only correct regarding the example of Marc with non-static imports which only imports types (classes and interfaces). Of course Rob is right.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!