“意外的类型所需类中的类型参数攻击”

问题描述:

这是我的代码(尝试写我的类定义拷贝构造函数):“意外的类型所需类中的类型参数攻击”

public class ArgumentTree<GameArgument, Attack> extends DelegateTree<GameArgument, Attack> 
{ 
    public ArgumentTree() 
    {super();} 

    public ArgumentTree(ArgumentTree<GameArgument, Attack> sourceTree) 
    { 
     super(); 
     Attack atck = new Attack(); // I get the Error here 
     more code.... 
    } 
} 

我收到此错误:

unexpected type 
required: class 
found: type parameter Attack 

刚澄清:我不想让代码具有通用性。我已经知道我将使用的类型只有GameArgument和Attack。另外,Attack有它自己的默认构造函数。

+0

你的代码*是*通用的,无论你是否需要它。 – 2012-07-23 13:08:01

您正在使用实际的类名作为类型变量。这没有意义。也许你想要类似

public class ArgumentTree extends DelegateTree<GameArgument, Attack> 
+0

感谢Marko,解决了我的问题。 – Ali 2012-07-23 13:10:15