How to import a class from default package

后端 未结 9 931
盖世英雄少女心
盖世英雄少女心 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:23

    From some where I found below :-

    In fact, you can.

    Using reflections API you can access any class so far. At least I was able to :)

    Class fooClass = Class.forName("FooBar");
    Method fooMethod =
        fooClass.getMethod("fooMethod", new Class[] { String.class });
    
    String fooReturned =
        (String) fooMethod.invoke(fooClass.newInstance(), "I did it");
    

提交回复
热议问题