You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2023/05/09 08:31:10 UTC

[GitHub] [incubator-pekko] He-Pin commented on a diff in pull request #316: Add OptionConverters.toScala methods for java Optional primitives

He-Pin commented on code in PR #316:
URL: https://github.com/apache/incubator-pekko/pull/316#discussion_r1188308742


##########
actor/src/main/scala-2.12/org/apache/pekko/util/OptionConverters.scala:
##########
@@ -21,9 +21,21 @@ import java.util._
 @InternalStableApi
 private[pekko] object OptionConverters {
   import scala.compat.java8.OptionConverters.SpecializerOfOptions
+  import scala.compat.java8.OptionConverters._
 
   @inline final def toScala[A](o: Optional[A]): Option[A] = scala.compat.java8.OptionConverters.toScala(o)
 
+  // The rest of the .toScala methods that work with OptionalDouble/OptionalInt/OptionalLong have to be manually
+  // redefined because the scala.compat.java8.OptionConverters.toScala variants work with scala.lang primitive types
+  // where as scala.jdk.javaapi.OptionConverters.toScala works with java.lang primitive types. Since the primary
+  // usecase of these functions is for calling within Java code its preferrable to return Java primitives, see
+  // https://github.com/scala/bug/issues/4214
+  def toScala(o: OptionalDouble): Option[java.lang.Double] = if (o.isPresent) Some(o.getAsDouble) else None

Review Comment:
   I think that's fine, @inline is only applied if you compile with it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org