Cannot Compile Call to clone()
on Java Interface That Defines It.
#10501
Labels
Milestone
clone()
on Java Interface That Defines It.
#10501
In Java, interfaces are allowed to define that their implementations must expose public
clone()
methods (the example reference here isIonValue
from the package ion-java).For some reason, the scala compiler (tested with 2.11.8 and 2.12.3) doesn't "see" these overridden methods, instead trying and failing to compile against
Object.clone
, which is protected.Scala's behavior when trying to implement something similar via a
trait
seems to allude to what the problem is:That, in and of itself, is fine. Scala doesn't allow you to do this, and that's ok. The problem is that Java does allow this, as seen in ion-java. This ultimately creates Java code that is impossible to call from Scala (presumably because Scala's rules for precedence in the face of inheritance differs slightly from Java, but that's just a hunch). Here is what happens when you try to call
clone()
as defined on a Java interface:The problem here is that Java has allowed code that defines
clone()
in an interface to be compiled, and when that code is called from Java, it is then allowed to be accessed. However (seemingly because of Scala's slightly different rules for abstract methods), it is impossible to call these methods without reflection.The expected behavior, of course, is that you can call
clone()
as defined on interfaces from Scala in more or less exactly the same way as you can from Java.The text was updated successfully, but these errors were encountered: