How to import a class from default package

后端 未结 9 926
盖世英雄少女心
盖世英雄少女心 2020-11-22 11:02

Possible Duplicate: How to access java-classes in the default-package?


I am using Eclipse 3.5 and I have created a project with so

9条回答
  •  清歌不尽
    2020-11-22 11:13

    Unfortunately, you can't import a class without it being in a package. This is one of the reasons it's highly discouraged. What I would try is a sort of proxy -- put your code into a package which anything can use, but if you really need something in the default package, make that a very simple class which forwards calls to the class with the real code. Or, even simpler, just have it extend.

    To give an example:

    import my.packaged.DefaultClass;
    
    public class MyDefaultClass extends DefaultClass {}
    package my.packaged.DefaultClass;
    
    public class DefaultClass {
    
       // Code here
    
    }

提交回复
热议问题