Re: Different behaviour from Option map in scala compared to Optional map in java
Simon Ochsenreither <[email protected]> Sun, 17 Apr 2016 14:20:12 -0700 (PDT)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
> you're right it's not a bug, but I normally think that getting a Some > object means that it does not contain null, because null would be > represented with None. > This thinking leads to a NullPointerException when I try to use the > contained value in the returned Some object. > This is strange in my eyes because I would use the map method from Option > to prevent getting NullPointerExceptions. > Therefore I think it's more intuitive if map returns Option(f(this.get)) > instead of Some(f(this.get)), because this would prevent a > NullPointerException if I use the returned Option object from map. > Option[T] doesn't (and can't) add additional constraints on T. If null is a valid value of T, Some(null) is a perfectly fine value of Option. Adding ad-hoc null-handling to some types would be more or less just trying to paper over the issue that most things in Scala/on the JVM are nullable. The problem should be fixed (maybe in Dotty), not the symptoms. -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.