edge cases for compiler/parser

i have a interface with the following source
package com.hsbc.haf.services;

import com.hsbc.haf.services.HAFService;
/**

  • The HafService is a marker interface so that all subclasses can be identified as being a Haf service.

*/
public interface HAFService {
}

IDEA parser refuses to parse/compile it saying "HAFService is already compiled in this compilation unit".
Fact is, this is indeed strange, the import clause imports the very same class that is defined in the file.
Any idea is this legal java source ? or is it a "bug" (or limitation) in IDEA parsing/compiling?

ps: the following code compiles/parses ok in WSAD (based on Eclipse).

1 comment
Comment actions Permalink

No, IDEA is right. Single-type import brings HAFService name into the scope of compilation unit, and it is an error to define the class with the same name. The error does not happen if you use on demand import - then your class simply hides imported name in the compilation unit.

0

Please sign in to leave a comment.