Reputation: 6620
Why does Eclipse add an import for the target class of a Javadoc @see comment?
If you run this through findbugs or PMD they complain that its an unused import.
So which is correct? Personally I can't see why eclipse wants to import it.
import java.util.List;
/**
* @see List
*/
The same is true for 'link'
import java.util.List;
/**
* {@link List}
*/
Does any have any ideas why?
Upvotes: 4
Views: 1333
Reputation: 21984
The only reason Eclipse does that is, so that while going over your source code, you could do a command click (ctrl + click) and navigate to the class in @see.
Otherwise your class name will not have context. The only other workaround is to give full context path in see also. (along with package name).
Upvotes: 1
Reputation: 74750
I don't know about Eclipse, but Javadoc needs the import if you don't write the full name in the {@link}
or @see
tag. So you could try
@see java.util.List
instead.
Upvotes: 3
Reputation: 20371
The important thing to understand about import statements are that they are simply a convenience mechanism for the developer to avoid having to use the Fully Qualified Name (FQN) for a Type
everywhere. For example, importing java.util.List
will let you refer to it by simply using the simple name List
as opposed to using java.util.List
everywhere.
Imports have no effect on the efficiency or size of the generated bytecode since their use is as explained above and they do not cause any classes to be 'linked' or anything like that with your class.
In the case of the JavaDoc comments, if you use the FQN , Eclipse wouldn't need to import in order to resolve the Type
reference. As it is, you're using the simple name which is ambiguous so Eclipse imports the appropriate Type
.
Upvotes: 9
Reputation: 30934
An unused import is one that is not needed by the Java compiler.
So PMD is right about flagging it.
Upvotes: 0