"意外类型需要类找到类型参数攻击"

Ali*_*Ali 2 java generics copy-constructor type-parameter

这是我的代码(尝试为我的类编写一个复制构造函数):

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....
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

unexpected type  
 required: class  
 found:   type parameter Attack  
Run Code Online (Sandbox Code Playgroud)

只是为了澄清:我不想让代码通用.我已经知道我将使用的类型只是GameArgument和Attack.此外,Attack有自己适当的默认构造函数.

Mar*_*nik 8

您使用实际的类名作为类型变量.这没有意义.也许你想要的东西

public class ArgumentTree extends DelegateTree<GameArgument, Attack>
Run Code Online (Sandbox Code Playgroud)