반응형
Scala에서 특성 및 추상 메서드 재정의
기본 추상 클래스 (특성)가 있습니다. 거리 인 방법이 foo()
있습니다. 파생 파생 클래스에 의해 확장되고 구현됩니다. 파생 클래스에 혼합 할 수있는 특성을 foo()
파생 클래스의 foo()
.
다음과 같은 것 :
trait Foo {
def foo()
}
trait M extends Foo {
override def foo() {
println("M")
super.foo()
}
}
class FooImpl1 extends Foo {
override def foo() {
println("Impl")
}
}
class FooImpl2 extends FooImpl1 with M
자체 유형과 구조 유형을 시도했지만 작동하지 않습니다.
당신은 아주 가까웠습니다. M.foo에 추상 수정 튼튼 추가하면 'Stackable Trait'패턴이 생생합니다 : http://www.artima.com/scalazine/articles/stackable_trait_pattern.html
trait Foo {
def foo()
}
trait M extends Foo {
abstract override def foo() {println("M"); super.foo()}
}
class FooImpl1 extends Foo {
override def foo() {println("Impl")}
}
class FooImpl2 extends FooImpl1 with M
참고 URL : https://stackoverflow.com/questions/2038370/traits-and-abstract-methods-override-in-scala
반응형
'ProgramingTip' 카테고리의 다른 글
Postgresql- 데이터베이스 백업 및 다른 소유자로 복원? (0) | 2020.12.01 |
---|---|
그래프에서 "좋은"격자 선 간격을위한 알고리즘 (0) | 2020.12.01 |
UIWebView에서 앱 URL을 처리하는 방법은 무엇입니까? (0) | 2020.12.01 |
PDF를 병합하는 Ghostscript는 결과를 압축합니다. (0) | 2020.12.01 |
Python mock의 모의 속성? (0) | 2020.12.01 |