账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    scala Some(variable)作为方法Option参数的默认值无法编译
    27
    0

    使用Some(salt),Option(salt)作为方法参数默认值无法通过编译

    case 1 使用Some(salt)作为参数默认值无法通过编译

    object Digest {
      import utils.Hex._
    
      val salt = Configuration.load(Environment.simple()).get[String]("hash.salt")
    
      def digest(s: String, salt: Option[String] = Some(salt)): String = {
        ...
      }
    }
    [info] Compiling 1 Scala source to /home/xiao/weibos_service/target/scala-2.12/classes ...                                                        
    [error] /home/xiao/weibos_service/app/utils/encrypt/Digest.scala:12:55: type mismatch;
    [error]  found   : Option[String]                                                                   
    [error]  required: String                                                                             
    [error]   def digest(s: String, salt: Option[String] = Option(salt)): String = {                       
    [error]                                                       ^                                       
    [error] one error found                                                                                
    [error] (compile:compileIncremental) Compilation failed                                                
    [error] Total time: 1 s, completed 2018-3-14 17:41:30                  

    case 2 使用另一个新的成员saltOpt=Some(salt)作为参数默认值就能通过编译了

    object Digest {
      import utils.Hex._
    
      val salt = Configuration.load(Environment.simple()).get[String]("hash.salt")
      private val someSalt = Option(salt)
    
      def digest(s: String, salt: Option[String] = someSalt): String = {
        ...
      }
    }

    ???

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 芥湖泊舟 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部