저는 스칼라를 처음 사용하기 때문에 연습 만하고 있습니다. 에서 변수 nextDevice 때문에, 클래스 입력이 추상적 할 필요가 : 추상 클래스를 사용한 스칼라 상속
abstract class Device(val cds: Array[Char]) { var codes = Array[Char](cds: _*) def encrpt(code: Char): Char var nextDevice: Device def setNext(next: Device):Unit = { nextDevice = next } } //compiler error shows here class Input(codes: Array[Char]) extends Device(codes) { override def encrpt(code: Char) = code }
당신이 거기에 라인 (21)에서 컴파일러 오류가 있습니다 다음 볼 수 는 메시지입니다
: 나는, 아주 간단한 프로그램을 시도 은 다음과 브리핑 형 com.me.acm.problem1009.Device의 클래스 장치는,은 내가 꽤 혼동하는 오류, 내 이해 (변수를 정의 할 수 초기화해야합니다) 어떤 변수와 정의 정의되지 입니다 setter 메서드를 부모 클래스에서 사용하므로 자식 클래 ses는 그것을 다시 정의하지 않고 사용할 수 있습니다. 그것은 곧장 앞으로입니다.
내가 놓친 것 같아. 누군가 나에게 설명하고 올바른 방법이 무엇인지 말할 수 있습니까? 감사.
참고 명시 적 getter 및 setter, VAR 선언은 선언 할 필요가 없습니다 암시 적으로 getter와 setter로 확장되었습니다. 구체적인 멤버에게 어떻게 발생하는지 [this] (http://www.artima.com/pins1ed/stateful-objects.html#18.2)와 [that] (http://www.artima.com/pins1ed/) abstract-members.html # 20.4). – huitseeker