Different behaviour from Option map in scala compared to Optional map in java

Marc Arndt <[email protected]> Sun, 17 Apr 2016 03:27:09 -0700 (PDT)
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
Hello,
while programming with java 8 and scala I discovered that both seem to have 
a different behaviour with the method map in the classes Option in scala 
and Optional in java.
In scala the method map in Option is implemented as followed:


*  @inline final def map[B](f: A => B): Option[B] =    if (isEmpty) None 
else Some(f(this.get))*This method requires, that f doesn't return null.

In java the method map in Optional is implemented as followed: 







*    public<U> Optional<U> map(Function<? super T, ? extends U> mapper) 
{        Objects.requireNonNull(mapper);        if 
(!isPresent())            return empty();        else {            return 
Optional.ofNullable(mapper.apply(value));        }    }*
This method does not require, that the given method returns a value not 
null, it is also accepted to return null.

I'm not sure if this behaviour is intended.

Many Greetings
Marc

-- 
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.