Marc Arndt
2016-04-17 10:27:09 UTC
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
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 scala-language+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 scala-language+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.