How to access java-classes in the default-package?

前端 未结 5 1655
有刺的猬
有刺的猬 2020-11-21 13:18

I\'m working now together with others in a grails project. I have to write some Java-classes. But I need access to an searchable object created with groovy. It seems, that t

5条回答
  •  既然无缘
    2020-11-21 14:23

    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", String.class);
    
    String fooReturned = (String)fooMethod.invoke(fooClass.newInstance(), "I did it");
    

提交回复
热议问题