我正在尝试编译这个新类:
public class WindowedGame
extends GameContainer<GameType extends Game<Graphics2D>> {
...
}
这个类扩展类:
public abstract class GameContainer<GameType extends Game<?>> {
....
}
您能否建议我更正或向我解释为什么会出现错误:
Unexpected bounds
谢谢!
最佳答案
GameType
是泛型类型参数名,不能出现在extends
子句中。
如果 WindowedGame
应该是通用的,将其定义为
public class WindowedGame<GameType extends Game<Graphics2D>>
extends GameContainer<GameType> {
...
}
如果 WindowedGame
不应该是通用的,也许您打算将其定义为
public class WindowedGame
extends GameContainer<Game<Graphics2D>> {
...
}
顺便说一句,泛型类型参数名称的命名约定通常是单个大写字符(T
、E
等...)。如果将 GameType
写成 T
就不会那么困惑了。
public class WindowedGame<T extends Game<Graphics2D>>
extends GameContainer<T> {
...
}
public abstract class GameContainer<T extends Game<?>> {
....
}
关于java - 意外绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41357479/