I have this helper to simplify null asserts:
object Helpers {
implicit class NotNullAssert[T](val obj: T) extends AnyVal {
def ! : T = {
assert(obj != null); obj
}
}
}
Now I am trying to use it:
import Helpers._
class Name(val first: String, val last: String) {
val full = first! + " " + last!
}
Getting a compilation error:
Error:(8, 27) value unary_+ is not a member of String
val full = "" + first! + " " + last!
The same time, the following works:
val full = first! //+ " " + last!
What is going wrong in the fragment above?
first!is "post-fix notation" and confuses the compiler when used in longer expressions. Tryfirst.!and see what happens.