如何扩展可扩展App的类

时间:2018-07-17 18:50:28

标签: scala

我有一个主基类,我想对其进行扩展,以便该主类为扩展类提供基本功能:

class Foo extends App {
  println("Foo")
  def bar = {}
}

class Foo2 extends Foo {
  println("Foo2")
}

object Foo2 extends Foo2 {

}

但这不起作用。编译器抱怨warning: Foo2 has a main method with parameter type Array[String], but Foo2 will not be a runnable program. Reason: companion contains its own main method, which means no static forwarder can be generated.

如何实现?

1 个答案:

答案 0 :(得分:2)

您的代码中名称不明确。只需重命名类或对象,就可以了

function (val, max, min) {
    if(max - min === 0) return 1 // or 0, it's up to you
    return a + (((val - min) * (b-a)) / (max - min));
}