to-6ren">
gpt4 book ai didi

Scala编译错误 “value max is not a member of Int"

转载 作者:行者123 更新时间:2023-12-02 18:44:26 27 4
gpt4 key购买 nike

在下面的代码中:

case class Token(name: String, number: Int)


tokensDAO.getTokenSeq().map(

tokenSeq => tokenSeq.map(_.number).fold(0)(_ max _)

)

导致此编译错误的可能原因是什么?

value max is not a member of Int

从 JDBC 数据库检索 tokenSeq 时,可能会重现该错误。它是 Play Framework 上的 HikariCP 连接池。

由于问题是通过 import Predef.intWrapper 解决的(通常不需要),因此包含完整的导入以供进一步审查:

import java.io.{ File, PrintWriter }
import models.{ DownloadToken, User }
import models.daos.{ DownloadDAO, UserDAO }
import Predef.intWrapper
import java.util.UUID

import scala.util.Random

import java.security.SecureRandom
import javax.inject.Inject
import scala.concurrent.{ ExecutionContext, Future }

import java.util.Base64

这是类的签名:

class DownloadServiceImpl @Inject() (downloadDAO: DownloadDAO, userDAO: UserDAO, configuration: play.api.Configuration)(implicit ex: ExecutionContext) extends DownloadService

这是评论中要求的 build.sbt 上完整的 scalacOptions:

scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
//"-Xlint", // Enable recommended additional warnings.
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
// Play has a lot of issues with unused imports and unsued params
// https://github.com/playframework/playframework/issues/6690
// https://github.com/playframework/twirl/issues/105
"-Xlint:-unused,_"
)

最佳答案

max 通过隐式扩展方法在 Int 上提供。尝试一下

import Predef.intWrapper
tokensDAO.getTokenSeq().map(...)

如果有效,则可能是某些东西干扰了 scala.Predef 的默认导入。

关于Scala编译错误 “value max is not a member of Int",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67651315/

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