July 13, 2011

Importing a class from default package - Impossible

Did you know that classes in the ‘default package’ (classes that don’t have a package) cannot be imported from classes that do have a package?

I did not know that.

Try it:



Now try to compile your code:
>javac Class1.java

>javac package2\Clazz2.java -cp .

package2\Clazz2.java:3: ‘.’ expected
import Class1;
^
package2\Clazz2.java:3: ‘;’ expected
import Class1;

How stupid is this?
Is this why omitting package is deprecated?

No comments:

 

Copyright 2007 All Right Reserved. shine-on design by Nurudin Jauhari. and Published on Free Templates