Suppose I have a method session.get(str: String): String but you don’t know whether it will return you a string or a null, because it comes from Java.
Is there an easier way to treat this in Scala instead of session.get("foo") == null ? Maybe some magic apply like ToOption(session.get("foo")) and then I can treat it in Scala way like
ToOption(session.get("foo")) match {
case Some(_) =>;
case None =>;
}
The
Optioncompanion object’sapplymethod serves as a conversion function from nullable references: