Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To understand the reason your code doesn't compile, first note that Java uses <code>java.lang.Boolean</code> for the boxed boolean type, and Scala uses <code>scala.Boolean</code>. Most of the time, when you want to use one of them, and a method returns the other one (or a method argument requires the other one), an implicit conversion will be performed, and the correct type will be used.</p> <p>The method <code>a</code> that you wrote in Scala really returns <code>A[java.lang.Boolean]</code>. Because there's no implicit conversion between <code>A[java.lang.Boolean]</code> and <code>A[scala.Boolean]</code>, it will not automatically return <code>A[scala.Boolean]</code> in this case.</p> <p>To verify that this is the case, we can see that this method compiles without issues:</p> <pre><code>def a: A[java.lang.Boolean] = new AT() </code></pre> <p>To reiterate the point, because we don't have the implicit conversion, this will also not work (you'll see how that can be fixed below):</p> <pre><code>val instanceOfA: A[Boolean] = a def a = new AT() // Error: AT doesn't conform to A[Boolean] </code></pre> <p>To fix it, you could implicitly convert to the needed type by casting it:</p> <pre><code>implicit def toScalaABoolean(a: A[java.lang.Boolean]): A[Boolean] = a.asInstanceOf[A[Boolean]] </code></pre> <p>With that done, you don't even have to declare the return type of <code>a</code> method anymore:</p> <pre><code>implicit def toDifferentBoolean(a: A[java.lang.Boolean]): A[Boolean] = a.asInstanceOf[A[Boolean]] val instanceOfA: A[Boolean] = a def a = new AT() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload