3

How do I use Queue here?

I can't get the import to work because Queue.class is not in a package.

I have tried everything in this universe, and more.

image https://i.stack.imgur.com/AFrrc.jpg

Sam
  • 1,509
  • 3
  • 19
  • 28
Eratox
  • 33
  • 1
  • 3

1 Answers1

6

Your Queue class is under unnamed package (refer JLS). It can't be imported. Also, it's bad practice.

You have two options

  1. Move your own code to unnamed package. Theoretically, both of them being in same package, you will not need to import Queue as it's class-name is suffice to find out the class.

  2. Use JarJar - a tool to repackage your Jar files. Repackage the Jar containing the Queue class and move the unnamed package to a sensible package name. Use Fully Qualified Class Name (FQCN) to import.

I would suggest to use packages and go for option 2.


Edit 1: also see this What's the syntax to import a class in a default package in Java?

Community
  • 1
  • 1
Nishant
  • 54,584
  • 13
  • 112
  • 127
  • Thank you for that, now I udnerstand how it works. The Jar-file was provided by my teacher to be used in the lab assignment, heh. – Eratox Feb 13 '11 at 13:40