【问题标题】:"Unexpected type required class found type parameter Attack"“意外类型所需类发现类型参数攻击”
【发布时间】:2012-07-23 13:05:41
【问题描述】:

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

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 有自己的适当默认构造函数。

【问题讨论】:

  • 你的代码通用的,不管你想不想。

标签: java generics copy-constructor type-parameter


【解决方案1】:

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

public class ArgumentTree extends DelegateTree<GameArgument, Attack>

【讨论】:

    猜你喜欢
    • 2014-12-03
    • 2020-10-17
    • 2017-04-20
    • 1970-01-01
    • 2021-12-27
    • 2012-12-12
    相关资源
    最近更新 更多