scala - 为什么我的 scala 代码在 IntelliJ IDEA 中工作但在 cmd 中报告错误?
问题描述
Scala新手。我想验证我的配置文件是否正确,所以我编写了一个helloword程序。
object HelloWorld{
def main(args : Array[String]){
println("HelloWorld")
}
}
当它在 cmd 中“scalac”文件时说warning: 1 deprecation (since 2.13.0); re-run with -deprecation for details 1 warning
但在 IDEA 中,代码有效。怎么了?
解决方案
如果您要添加build.sbt
以下行:
ThisBuild / scalacOptions ++= Seq("-deprecation", "-Xfatal-warnings")
当出现此类弃用警告时,它将导致您的编译失败。这始终是一个好习惯。如果添加它,您将收到以下编译错误:
[error] procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `main`'s return type
[error] def main(args : Array[String]){
然后,在应用建议时,并添加返回类型,例如:
object HelloWorld {
def main(args : Array[String]): Unit = {
println("HelloWorld")
}
}
您没有收到任何警告并按HelloWorld
预期打印。
推荐阅读
- asterisk - 无法在任何版本上安装 meetme
- angular - TypeScript 上缺少属性“包含”
- apache-camel - 如何使用骆驼为文件添加签名
- c++ - c++ 可选(T) -> 可选
- javascript - 为什么不能用 show 函数写 id=show 属性?
- c++ - 在奇怪的情况下跳过内部捕获
- android - 保护我的应用免于模拟 API 响应
- java - startActivity 不等待警报按钮被点击
- javascript - 从 SharePoint 列表中获取不同的数据并推入表中
- java - mvn clean install 时出错 - MojoExecutionException