props.put("retries", 3)报错,对于这种字面值如何指定类型呢?
Error:(13, 24) type mismatch;
found : Int(3)
required: Object
Note: an implicit exists from scala.Int => java.lang.Integer, but
methods inherited from Object are rendered ambiguous. This is to avoid
a blanket implicit which would convert any scala.Int to any AnyRef.
You may wish to use a type ascription: `x: java.lang.Integer`.
props.put("retries", 3)
只能按照使用一个临时变量吗? val x : java.lang.Integer = 3
有没有其他更加优雅的写法呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
3.instanceOf[Integer]也不好看 凑合用吧
如果你只写一次,可以用
instanceOf如果需要写很多次,可以利用隐式转换简化,更简单的方式是写个辅助的函数