내가 자주 다음과 같은 문제가 발생하고 다음 AuctionParticipantActor
Akka 배우와의 분산이 올바른가요? 제네릭 및 Akka 배우를 사용하는 경우
trait AuctionParticipantActor[P <: AuctionParticipant[P]]
extends StackableActor {
override def receive: Receive = {
case message: Handled =>
participant = participant.handle(message)
super.receive(message)
case message =>
super.receive(message)
}
protected var participant: P
}
것은 불변의 AuctionParticipant
주변 단지 래퍼입니다. 나는 타입이 P
이 공변 (covariant)해야하고 이것을 성취하는 가장 좋은 방법이 무엇인지 모르겠습니다.
또는 내 사용 사례에 대해서는 AuctionParticipantActor
을 매개 변수화 할 필요가 없다고 생각합니다. 나는 다음과 같은 것을 가질 수있다 :
trait AuctionParticipantActor
extends StackableActor {
override def receive: Receive = {
case message: Handled =>
participant = participant.handle(message)
super.receive(message)
case message =>
super.receive(message)
}
protected var participant: AuctionParticipant[???]
}
그러나이 경우에, 나는 무엇 대신 넣을 지 모르겠다. 바인딩 된 타입을 존중하기 위해서. 누군가 내 문제가 디자인에 있다고 생각한다면 그렇게 말하십시오. 생각?
명확하게하기 위해, 나는 AuctionParticipant'에 대한 F-경계 다형성이 필요 'trait (이 특성의 메서드는 하위 클래스를 반환합니다.) 그렇기 때문에 실재 형식 매개 변수는 형식 범위를 위반하므로 컴파일되지 않을 것이라고 생각합니다. – davidrpugh
@davidrpugh 당신은 'AuctionParticipant'의 정의를 작성하지 않았습니다. 나는 당신이 당신의 질문을 업데이트해야한다고 생각합니다. –
@davidrpugh 존재 유형이 다를 수 있습니다. 필요한 경우 AuctionParticipant [_ <: UpperBound] 또는 'AuctionParticipant [_> : LowerBound]'가 될 수 있습니다. 'protected var participant : AuctionParticipant [_ <: AuctionParticipant [_]]는 어떻습니까? 그것은 컴파일합니까? –