I recently ended up with something like this:
object Implicits {
implicit class ConvertToOption[T](t: T) {
def optional = Option(t)
}
}
Usage:
Suppose you have a following Java interface:
public interface Fooable {
public String getFoo();
}
public class Foo implements Fooable {
public String getFoo() {
return null;
}
}
In your Scala code:
import Implicits._
val foo = new Foo()
val myOptionalValue = foo.getFoo.optional //returns an Option[String], in this case None because getFoo returns null