현재 여러 유형 매개 변수에 대한 하나의 특성을 따르는 객체/클래스/특성을 작성하는 것에 대해 궁금합니다. 내 IntStrDependent
특성의 인스턴스가있을 것이다 그래야 예를동일한 특성이지만 다른 유형 매개 변수가있는 조합
trait IntStrDependent extends Dependent[Int] with Dependent[String]
를 들어, 내가
trait Dependent[T]{
def observeCritereaChanged(oldValue:T, newValue:T):Unit
}
내가 두 개의 서로 다른 유형의 매개 변수에 대한 종속 구현하는 몇 가지 특성을 정의 할 수 있도록하고 싶습니다 있다고 가정 해 봅시다 두 가지 유형의 observeCritereaChanged
을 정의
class MyDependent extends IntStrDependent {
def observeCritereaChanged(oldValue:Int, newValue:Int) = //...
def observeCritereaChanged(oldValue:String, newValue:String) = //...
}
하려고 할 때
지금까지 나의 노력은 컴파일 오류와 함께 충족 IntStrDependent
특성을 만들 수 있습니다 :
scala> trait IntStrDependent extends Dependent[Int] with Dependent[String]
<console>:8: error: illegal inheritance;
self-type IntStrDependent does not conform to Dependent[Int]'s selftype Dependent[Int]
trait IntStrDependent extends Dependent[Int] with Dependent[String]
^
<console>:8: error: illegal inheritance;
self-type IntStrDependent does not conform to Dependent[String]'s selftype Dependent[String]
trait IntStrDependent extends Dependent[Int] with Dependent[String]
^
그래서 내 질문은 : 내가 할 노력하고있어 (그렇다면, 어떻게) 또는 스칼라가에 내장되어 있지 않기 때문에이 분실 된 원인이 무엇인지 할 수있는 방법이 있나요 이런 종류의 일을합니까?
그게 제가 보통하는 것입니다. –
흥미로운 당신이 링크를 읽었습니다. 그건 분명히 내 질문에 대한 답변,하지만 난 당신의 접근 방식과 함께 갈 것 : 내 응용 프로그램에 대한'괜찮아야한다'a에서'a '관계로 전환 – Dylan