Учитывая такую особенность:Перекрытие Метод (Int => Int => Int) из Trait
scala> trait Foo {
| def f: Int => Int => Int
| }
defined trait Foo
Я создал класс, который пытался создать экземпляр Foo#f
:
scala> class FooImpl extends Foo {
| override def f(x: Int, y: Int) = 100
| }
<console>:11: error: class FooImpl needs to be abstract, since method f in trait Foo of type => Int => (Int => Int) is not defined
class FooImpl extends Foo {
^
Я был в состоянии решить она с:
scala> class FooImpl extends Foo {
| override def f = x => y => 100
| }
defined class FooImpl
Тогда я могу сделать экземпляр:
scala> new FooImpl().f(10)(20)
res3: Int = 100
Но, как бы я создаю реализацию Foo
, который реализует Foo#f
с def f(x: Int, y: Int) = 100
, то есть без выделки?
Наконец, я попробовал:
scala> trait Bar { def f: (Int, Int) => Int }
defined trait Bar
Но это тоже не получилось:
scala> class BarImpl extends Bar {
| override def f(x: Int, y:Int) =100
| }
<console>:11: error: class BarImpl needs to be abstract, since method f in trait Bar of type => (Int, Int) => Int is not defined
class BarImpl extends Bar {
^