【发布时间】:2014-10-21 07:20:53
【问题描述】:
我有
LoginCommandExecutor implements CommandExecutor<LoginCommand>
LoginCommand implements Command
为什么这行会抛出编译错误:
CommandExecutor<Command> a = new LoginCommandExecutor(commander, null);
但它适用于以下两种情况:
CommandExecutor<? extends Command> a = new LoginCommandExecutor(commander, null);
CommandExecutor b = new LoginCommandExecutor(commander, null);
如果两者都工作,哪一个更可取?为什么?
因为我看到 a 和 b 在 IDE 中显示相同的方法
【问题讨论】:
标签: java generics inheritance interface