如何实例化一个类

时间:2014-05-24 21:35:38

标签: java graphiti

我的应用程序出了问题,我无法实例化一个类

这是我的java.lang.ClassCastException

eclipse.emf.editeurgraphique.risque.features.StartEventFeature$CreateStartEventFeature cannot be cast to org.eclipse.graphiti.features.ICreateFeature 
at eclipse.emf.editeurgraphique.risque.features.StartEventFeature.getCreateFeature(StartEventFeature.java:43)

这是我的方法:

 public ICreateFeature getCreateFeature(IFeatureProvider fp) {
    return (ICreateFeature) new CreateStartEventFeature(fp);
}

我的界面:

public interface ICreateFeature extends ICreate, IFeature {
 }

和我的班级

 public CreateStartEventFeature(IFeatureProvider fp) {
        super(fp, "Start Event", "Indicates the start of a process or    choreography");
    }

3 个答案:

答案 0 :(得分:0)

您的CreateStartEventFeature不会扩展您定义的任何类,因此通过调用超级构造函数

super(fp, "Start Event", "Indicates the start of a process or    choreography");

您尝试从Object类中运行参数化构造函数。

答案 1 :(得分:0)

CreateStartEventFeature需要实现接口:

public class CreateStartEventFeature extends MyBaseClass implements ICreateFeature 
{...}

答案 2 :(得分:0)

这个问题有点混乱,因为它没有显示整个问题,但我认为CreateStartEventFeature实现了ICreateFeature,所以试着省略显式的强制转换:

public ICreateFeature getCreateFeature(IFeatureProvider fp) {
    return new CreateStartEventFeature(fp);
}