Ethan Moore
Ethan Moore

Reputation: 401

Q : Why is my java.awt.event.*; import 'unused' yet I use it in my code?

Before you read through, I apologize if this question wastes your time.

It's not necessarily a problem, and my code runs fine in any case, so I don't necessarily need a problem solved. It's just more of a curious question.

In a Java file, I use java.awt.event.ActionListener quite frequently through out the code, yet, I don't have java.awt.event.ActionListener imported, and when I do import it, it tells me the import is unused? Is it that I have it imported in another file that is in the same package? Or is action listener just a generalized import, now? Again. Just curious, no actual problem.

Upvotes: 2

Views: 1300

Answers (3)

Aura
Aura

Reputation: 123

The only way you can avoid to import a class is whenever you have it in the same package as your own or if you are writing the fully qualified name.

Upvotes: 1

jseashell
jseashell

Reputation: 755

if you have

import java.awt.event.*;
import java.awt.event.ActionListener;

then I believe the specific import is just getting ignored because your code already imported everything from java.awt.event but you'll have to post some code to get a definitive answer. Your question is a little confusing cause you say java.awt.event.* in the title but then java.awt.event.ActionListener in your description

Upvotes: 2

Sergey Chechenev
Sergey Chechenev

Reputation: 79

If you write in code full class name like java.awt.event.ActionListener, then no class import required. Try write ActionListener and you'll see, that import is needed.

Upvotes: 4

Related Questions