我收到以下两种方法的双重定义错误:
def apply[T](state: T, onRender: T => Graphic,
onMouseEvent: (MouseEvent, T) => T): GraphicPanel =
apply(state, onRender, onMouseEvent = Some(onMouseEvent))
和
def apply[T](state: T, onRender: T => Graphic,
onKeyEvent: (KeyEvent, T) => T): GraphicPanel =
apply(state, onRender, onKeyEvent = Some(onKeyEvent))
它们都是apply
具有签名的更通用方法的方法重载:
def apply[T](state: T, onRender: T => Graphic,
onTickEvent: Option[T => T] = None, fps: Int = 30,
onMouseEvent: Option[(MouseEvent, T) => T] = None,
onMouseMotionEvent: Option[(MouseEvent, T) => T] = None,
onMouseInputEvent: Option[(MouseEvent, T) => T] = None,
onKeyEvent: Option[(KeyEvent, T) => T] = None)
我会假设即使这些类KeyEvent
和MouseEvent
有一个共同的超类(InputEvent
),编译器应该仍然能够区分它们。但是,它抛出错误:
双重定义:方法 apply:[T](state: T, onRender: T => edu.depauw.scales.graphics.Graphic, someOnKeyEvent: (java.awt.event.KeyEvent, T) => T)edu.depauw。 scales.graphics.GraphicPanel 和方法 apply:[T](state: T, onRender: T => edu.depauw.scales.graphics.Graphic, onMouseEvent: (java.awt.event.MouseEvent, T) => T)edu第 115 行的 .depauw.scales.graphics.GraphicPanel 在擦除后具有相同的类型:(state: Object, onRender: Function1, someOnKeyEvent: Function2) edu.depauw.scales.graphics.GraphicPanel
有人知道发生了什么吗?诚然,我不知道“擦除后”这个短语是什么意思,所以也许解释一下它是如何工作的可能会有所帮助。