To understand the reason why your code does not compile, first notice that Java uses java.lang.Boolean for a buffered type with a buffer, and Scala uses scala.Boolean . In most cases, when you want to use one of them, and the method returns the other (or the method argument requires the other), an implicit conversion will be performed and the correct type will be used.
The a method you wrote in Scala really returns A[java.lang.Boolean] . Since there is no implicit conversion between A[java.lang.Boolean] and A[scala.Boolean] , it will not automatically return A[scala.Boolean] in this case.
To make sure this is the case, we see that this method compiles without problems:
def a: A[java.lang.Boolean] = new AT()
To repeat this point, because we do not have an implicit conversion, this also will not work (you will see how this can be eliminated below):
val instanceOfA: A[Boolean] = a def a = new AT()
To fix this, you can implicitly convert to the desired type by doing it:
implicit def toScalaABoolean(a: A[java.lang.Boolean]): A[Boolean] = a.asInstanceOf[A[Boolean]]
You donβt even have to declare the return type of method a :
implicit def toDifferentBoolean(a: A[java.lang.Boolean]): A[Boolean] = a.asInstanceOf[A[Boolean]] val instanceOfA: A[Boolean] = a def a = new AT()
source share