Skip to content

Cannot convert scala.Boolean to java.lang.Boolean automatically #12818

@He-Pin

Description

@He-Pin

With Code when using netty 4:

        val bootstrap = new ServerBootstrap()
        bootstrap
          .option(ChannelOption.SO_REUSEADDR, !Helpers.isWindows)
          .option(ChannelOption.TCP_NODELAY, true)
          .bind(sockaddr)
          .channel()

which gives:

[error]  found   : io.netty.channel.ChannelOption[Boolean]
[error]  required: io.netty.channel.ChannelOption[Any]
[error] Note: Boolean <: Any, but Java-defined class ChannelOption is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[error]         bootstrap.option(ChannelOption.TCP_NODELAY, true)

Which compiles if:

bootstrap
          .option(ChannelOption.SO_REUSEADDR, java.lang.Boolean.valueOf(!Helpers.isWindows))
          .option(ChannelOption.TCP_NODELAY, java.lang.Boolean.TRUE)

or

bootstrap
          .option(ChannelOption.SO_REUSEADDR, Boolean.box(!Helpers.isWindows))
          .option(ChannelOption.TCP_NODELAY, Boolean.box(true))

reproducer: https://github.com/He-Pin/scala2booleanBug master branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)java interop

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions