JDK-4648570 : Cannot import classes from unnamed packages (1.4 regression)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2002-03-07
  • Updated: 2002-03-07
  • Resolved: 2002-03-07
Related Reports
Duplicate :  
Description
JDK 1.4 doesn't allow importing classes that don't belong to any package.
This contradicts the JLS and is different from 1.3 behavior.

Example:
 ------- A. java -------
public class A {

    public void foo() {}

}
 ------- B. java -------
import B;

public class B {

    public void bar() {
        new A().foo();
    }

}

------- Sample run, JDK 1.3 (correct) --------
% javac A.java B.java
%
------- Sample run, JDK 1.4 (wrong) --------
% javac  A.java B.java
B.java:1: '.' expected
import B;
        ^
1 error
%
------- Java Language Specification, second edition requirement: ------

7.5.1 Single-Type-Import Declaration

A single-type-import declaration imports a single type by giving its canonical name, making it available under a simple name in the class and interface
declarations of the compilation unit in which the single-type import declaration appears.

     SingleTypeImportDeclaration:
             import TypeName ;

The TypeName must be the canonical name of a class or interface type; a compile-time error occurs if the named type does not exist. The named type
must be accessible (?6.6) or a compile-time error occurs.