Created
October 18, 2012 00:38
-
-
Save ymasory/3909209 to your computer and use it in GitHub Desktop.
(1) using scala.None in Java, and (2) converting com.google.common.base.Optional to scala.Option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.base.Optional; | |
import scala.None$; | |
import scala.Option; | |
public class ScalaLang { | |
public static <T> Option<T> none() { | |
return (Option<T>) None$.MODULE$; | |
} | |
public static <T> Option<T> toOption(Optional<T> opt) { | |
if(opt.isPresent()) { | |
return scala.Option.apply(opt.get()); | |
} | |
else { | |
return none(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment