Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option#orNull can't be used from java #10006

Closed
scabug opened this issue Oct 24, 2016 · 4 comments
Closed

Option#orNull can't be used from java #10006

scabug opened this issue Oct 24, 2016 · 4 comments

Comments

@scabug
Copy link

scabug commented Oct 24, 2016

Scala options are a pain to use in java, but they would be much more pleasant if you could orNull them. As it is today, they blow up with things like:

error] class AllOf implements RoutePredicate {
                       [error] blahblaaablhablah.java:24: method orNull in class scala.Option<A> cannot be applied to given types;
                       [error]   required: scala.Predef.$less$colon$less<scala.runtime.Null$,A1>
                       [error]   found: no arguments
                       [error]   reason: cannot infer type-variable(s) A1
                       [error]     (actual and formal argument lists differ in length)
                       [error]     String sanitizedPath = opt.orNull();
                       [error] Compile failed at Oct 24, 2016 1:38:55 PM [0.221s]

               compile(blabhlahblahblahbl/predicates:predicates) failed: Zinc compile failed.
@scabug
Copy link
Author

scabug commented Oct 24, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10006?orig=1
Reporter: Moses Nakamura (mosesn)

@SethTisue
Copy link
Member

it's not clear to me if this is even actionable (I suspect it is not, but I could easily be wrong)

I'm going to close the ticket, but we can reopen if someone can propose a solution plan. otherwise it's too open-ended for scala/bug

@Jasper-M
Copy link
Member

Jasper-M commented Mar 1, 2018

scala-java8-compat contains a conversion between Option and Optional. That's really the best you can do here, I think...

@NthPortal
Copy link

The purpose of the signature for Option.orNull is to prevent you from attempting to make non-nullable types (e.g. Int) null (I believe). You can still use Option.getOrElse(null) from Java though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants