첫 번째 오류 :서명에 'uncheckedVariance'와 스칼라 유형 불일치 오류 혼동
/Users/rob/Workspace/Boiled.scala:9: error: type mismatch;
found : DataSetup{type Mem <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem; def copy$default$1: List[Int]}; object Mem; type Memory = this.Mem}
required: DataSetup{type Mem <: Product with Serializable{val ids: List[Int]; def copy(ids: List[Int]): this.Mem; def copy$default$1: List[Int] @scala.annotation.unchecked.uncheckedVariance}; object Mem; type Memory = this.Mem}
val dataSetup = new DataSetup {
^
사랑스러운 그것이 아니다? 그것은 DataSetup
형질의 인스턴스를 만들려고 시도하는 선을 가리 킵니다. 물론 실제 코드의 끓인 버전입니다.
trait DataSetup {
type Memory <: AnyRef with Serializable
def run(): Memory
}
object Use {
val dataSetup = new DataSetup { // <---- error reported here
case class Mem(ids: List[Int])
type Memory = Mem
def run(): Memory = {
val ids = List(1,2,3)
Mem(ids)
}
}
}
나는 그것이 무엇에 관해 불평하는지 정말로 모른다. 누군가?
, 그것은 작동합니다. 서브 클래스는 클래스 또는 특성을 가진 추상 유형을 "구현"할 수 있습니다. – nafg
또 다른 작업 변형 :'val dataSetup = new'를'object dataSetup extend'로 변경하십시오. – nafg
또 다른 :'val dataSetup : DataSetup = ...'. 흥미롭게도, 2.9에서 오류 메시지는 조금 다르게 나타납니다 :'found : Use.dataSetup.type (기본 타입 ... ') – nafg