0

I imported class Logger from package java.util.logging by using import java.util.logging.Logger. In addition to that, as per requirement I need to import user created class from some other package. But the problem is, that class name also Logger[Created in user defined package]. I don't have permissions to change the name of that user defined class and package. Both classes have the static methods.

So I need to import two both classes, then what is feasible solution for this?

Bali C
  • 30,582
  • 35
  • 123
  • 152
Manivasu
  • 29
  • 1
  • 4
  • 6

4 Answers4

5

call the full class name, i.e. package.class.
for instance, if you would create some class named File, you could still use java.io.File without importing it.
imports only lets you use the shorter name. a class full name is prepended by it's package name

in your case, you have: some.user.package.Logger, so you could use it exactly like that.

some.user.package.Logger userLogger = new some.user.package.Logger();
java.util.logging.Logger realLogger = java.util.logging.Logger.getAnonymousLogger(); //or whatever...
gilad hoch
  • 2,846
  • 2
  • 33
  • 57
0

You have to specify the full path.

Logger logger = new Logger();
com.abc.Logger yourLogger = new com.abc.Logger();
Stanley
  • 5,057
  • 4
  • 34
  • 44
0

When using one of the classes with same name but different package,

use fully qualified class name like :

java.util.logging.Logger logger;
mypackage.Logger myLogger;
Abubakkar
  • 15,488
  • 8
  • 55
  • 83
0

best way is to use fully qualified class names where you are using them in the class, without importing anything

vishal_aim
  • 7,636
  • 1
  • 20
  • 23