Reputation:
I have an object with an implicit class:
object ModelUtils {
implicit class RichString(str: String) {
def isNullOrEmpty(x: String): Boolean = x == null || x.trim.isEmpty
}
}
However, when I try to use it, IntelliJ cannot find the isNullOrEmpty method:
"TestString".isNullOrEmpty
I've tried various imports to import the method to no avail. What am I missing?
Upvotes: 0
Views: 208
Reputation: 44918
The problem is probably not with the import itself, but rather with the unnecessary parameter x
. If you want to call .isNullOrEmpty
without any arguments, then you must use str
, not x
:
object ModelUtils {
implicit class RichString(str: String) {
def isNullOrEmpty: Boolean = str == null || str.trim.isEmpty
}
}
import ModelUtils._
println("TestString".isNullOrEmpty)
Upvotes: 5