tangguo

循环泛型

java

我正在尝试采取以下措施:

public interface Player<R>
{
    R takeTurn(Game game);
}

public interface Game
{
}

public class XPlayer
    implements Player<Interger>
{
    // XGame won't work because the interface takes Game
    public Integer takeTurn(final XGame game)
    {
        return (null);
    }
}

public class XGame
{
}

我要坚持的是我需要在Game和Player界面中进行哪些更改才能使仿制药正常工作(我停顿了一下,但头上还有些毛:-)特别是,我迷上了Player需要在哪里进行操作知道游戏的类型,并且游戏需要知道玩家的类型。


阅读 277

收藏
2020-10-16

共1个答案

小编典典

这不是泛型问题(Game未键入)。

这是一个继承问题。尝试这个:

public class XGame implements Game // added interface
2020-10-16