Skip to content

Instantly share code, notes, and snippets.

@ClintCombs
Created June 28, 2012 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ClintCombs/3013226 to your computer and use it in GitHub Desktop.
Save ClintCombs/3013226 to your computer and use it in GitHub Desktop.
Using Scala's Option from Java
package net.ccombs.scalaFromJava;
import scala.Some;
import scala.Option;
import scala.None;
/**
* OptionExample
*/
public class OptionExample {
/**
* Construct a Scala Option[T] from a given value.
*/
private static final <T> scala.Option<T> option(final T value) {
return (value != null)?new Some<T>(value):scala.Option.apply((T) null);
}
public static void main(final String args[]) {
final Some<String> s1 = (Some<String>) option("s1");
// this doesn't work
// final None n = (None) option(null);
final Option<String> n = option(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment