我有一个隐式类的对象:
object ModelUtils { implicit class RichString(str: String) { def isNullOrEmpty(x: String): Boolean = x == null || x.trim.isEmpty } }
但是,当我尝试使用它时,IntelliJ找不到isNullOrEmpty方法:
"TestString".isNullOrEmpty
我尝试了各种导入方法,但都没有成功。我错过了什么?
问题可能不在于导入本身,而在于不必要的参数 x . 如果你想打电话 .isNullOrEmpty str 十、
x
.isNullOrEmpty
str
十、
object ModelUtils { implicit class RichString(str: String) { def isNullOrEmpty: Boolean = str == null || str.trim.isEmpty } } import ModelUtils._ println("TestString".isNullOrEmpty)