SORU
10 Ocak 2010, Pazar


Özellikleri ve soyut yöntemler Scala geçersiz kılar

Baz soyut bir sınıf (özellik) var. 2* *soyut bir yöntemi vardır. Genişletilmiş ve çeşitli türetilmiş sınıflar tarafından yürütülmektedir. foo() uygular ve sonra türetilmiş sınıf foo() aramaları, böylece türetilmiş sınıfları içine karışabilir bir özellik oluşturmak istiyorum.

Gibi bir şey

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 

Kendi türleri ve yapısal türleri çalıştım, ama işe giremiyorum.

CEVAP
10 Ocak 2010, Pazar


Çok yakındın. M. foo soyut değiştirici ekleyin ve 'Özellik' deseni: 7**. mükemmel bir Yazıcı var

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

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Kayla Caton - Peet

    Kayla Caton

    23 HAZİRAN 2012
  • KendrickLamarVEVO

    KendrickLama

    9 ŞUBAT 2011
  • Sams Page :D

    Sams Page :D

    15 Mart 2009