Sunday, December 02, 2007

A limitation of Java

I accidentally encounter a limitation in Java that say we have a class called Foo without a package name , that is as follows

public class Foo {

public void doFoo(){

In the mean time let's say we have a class called Bar which has a package name called “bar” , then if you want try to create an instance of class Foo , you can not do that , so following is not possible

package bar;

public class Bar {

public void doSomething(){
Foo foo = new Foo();

The reason is , there is no way to import that class. You might have already encounter this before , but I found that today.


Aj said...

is it not possible to give the fully qualified name of the class at instantiation ? I don't really get why this cannot be made to work

Deepal Jayasinghe said...

The problem is it does not have a package name , as you can see in the example I have given.

If it has a package name then that very simple , but when there is no package name problem come in the picture. No solution :)