scala - 如何扩展一个扩展 App 的类
问题描述
我有一个主基类,我想扩展它,以便主类为扩展类提供基本功能:
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.
如何做到这一点?
解决方案
There is an ambiguous name in your code. Just rename the class or object and you'll be fine
class Foo extends App {
println("Foo")
def bar = {}
}
class FooX extends Foo {
println("Foo2")
}
object Foo2 extends FooX {
}
推荐阅读
- git - $ git status On branch master 你的分支和'origin/master'已经分道扬镳,分别有38个和9个不同的提交
- python - Python中关于None的条件语句
- python - pandas:在 DataFrameGroupBy 上应用时的错误处理
- c - 检查并对齐缓冲区
- azure-devops - 如何将 nupkg 文件推送到 Azure DevOps 源?
- qlikview - 在 qlikview 中,是否可以保持脚本窗口始终打开?
- javascript - 表单上单选按钮选择时的 Javascript VISIBLE 和 REQUIRED 字段
- django - Django:我的测试迁移引发了关键错误,但正常迁移很好。什么坏了,我该如何解决?
- javascript - 不要让用户输入错误的数据 - 改进 IP 地址验证 JavaScript
- python - pandas - 高效计算组合算术