[英]Instantiate an Object from an IType
I would like to know if Eclipse JDT is offering any API functions to instantiate an object from an IType
. 我想知道Eclipse JDT是否提供任何API函数来实例化
IType
对象。
We are using the Eclipse JDT search engine to retrieve classes with a particular interface, say Application
that looks like this: 我们正在使用Eclipse JDT搜索引擎来检索具有特定接口的类,例如
Application
,看起来像这样:
public interface Application {
void launch();
}
Using the JDT search engine, we are able to get an IType
object that represents a class that implements the Application
interface. 使用JDT搜索引擎,我们可以获得一个
IType
对象,该对象表示实现Application
接口的类。 Assume that the implementing class has a no-argument constructor. 假设实现类具有无参数构造函数。
What we try to achieve is to get a concrete Object
from the IType
. 我们试图实现的是从
IType
获得一个具体的Object
。 So, I would like to know if the JDT offers any API functions to do so. 因此,我想知道JDT是否提供任何API函数来这样做。
If it does, we will use it to instantiate the IType
. 如果是这样,我们将使用它实例化
IType
。 If it doesn't, we will locate the containing projects, build a ClassLoader
from it and then use reflection to instantiate the class directly. 如果不是,我们将找到包含的项目,从中构建一个
ClassLoader
,然后使用反射直接实例化该类。
Thansk in advance, Matt 提前感谢,马特
Nope. 不。 Reflection is the way to go.
反思是要走的路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.