gpt4 book ai didi

java - Scala 包对象getClass

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:16:24 25 4
gpt4 key购买 nike

我想为 Scala 包对象获取 java.lang.Class:

应用程序/package.scala:

package object app {
}

应用/Main.scala:

打包应用

object Main extends App {
val _ = app.getClass
}

编译失败:

object getClass is not a member of package app Note that app extends Any, not AnyRef. Such types can participate in value classes, but instances cannot appear in singleton types or in reference comparisons.

最佳答案

您可以在应用程序返回类中定义方法:

package object app {
def cls = getClass
}

关于java - Scala 包对象getClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39286272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com