다음 코드가 있지만 컴파일되지 않습니다. 문제는 내가 T가 Event의 서브 클래스 여야한다는 것입니다.스칼라의 제네릭 함수에 대한 도움말
scala.swing.Reactions.Reaction의 유형 PartialFunction [이벤트, 단위]
오류이다 : 유형 불일치; 발견 PartialFunction [T, 단위] 필요한 : scala.swing.Reactions.Reaction
import scala.swing.event.MousePressed
import scala.swing.Component
import scala.swing.Reactions
import reactive.EventSource
import reactive.EventStream
class TypeIssue {
type PartialAdapter[T] = (T => Unit) => PartialFunction[T, Unit]
def adMousePressed(c: Component)(f: MousePressed => Unit): PartialFunction[MousePressed, Unit] = {
case MousePressed(`c`, point, mods, clicks, triggersPopup) => f
}
def eventToStream[T](r: Reactions, ad: PartialAdapter[T]): EventStream[T] = {
val v = new EventSource[T] {}
r += ad(e => v.fire(e)) // error on this line
v
}
}
는 당신이'수입 scala.swing.event 등의 필요한'import'-문을 포함하는 경우, 그것은 매우 도움이된다 ._' 그것은 5 줄이 더 많지만, 100 명의 사용자 대신에, 어떤 수입이 필요한지 알아 내려고 노력하고 있습니다 ... - 그냥 시간 낭비 일뿐입니다. –
죄송합니다. 수입과 수업 선언으로 질문을 업데이트하여 쉽게 재현 할 수있게되었습니다. – mentics
이제 좋은 질문입니다. :) –