AbstractMethodError when inheriting trait from java abstract class and referencing val from the trait
See original GitHub issueThis is the exact same bug as in Scala 2: https://github.com/scala/bug/issues/12456
trait ScalaTrait {
def foo1: String
def foo2: String = "default foo value 2"
val val1: String
val val2: String = "default val value 2"
}
public abstract class JavaAbstractClass implements ScalaTrait {
public String javaFoo1() { return foo1(); }
public String javaFoo2() { return foo2(); }
public String javaVal1() { return val1(); }
public String javaVal2() { return val2(); }
}
import scala.util.Try
object ScalaClass extends JavaAbstractClass {
override def foo1: String = "implemented foo in scala 1"
override val val1: String = "implemented val in scala 1"
def main(args: Array[String]): Unit = {
println(Try(javaFoo1()))
println(Try(javaFoo2()))
println(Try(javaVal1()))
println(Try(javaVal2()))
}
}
problem
The program compiles fine, but an exception is thrown at runtime:
Success(implemented foo in scala 1)
Success(default foo value 2)
Success(implemented val in scala 1)
Exception in thread "main" java.lang.AbstractMethodError: Method ScalaClass$.val2()Ljava/lang/String; is abstract
at ScalaClass$.val2(ScalaClass.scala)
at JavaAbstractClass.javaVal2(JavaAbstractClass.java:6)
at ScalaClass$.$anonfun$main$4(ScalaClass.scala:12)
at scala.util.Try$.apply(Try.scala:210)
at ScalaClass$.main(ScalaClass.scala:12)
at ScalaClass.main(ScalaClass.scala)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
AbstractMethodError when inheriting trait from java abstract ...
NOTE: I have to use an intermediate java class in my Scala classes hierarchy to workaround some other compiler issues. The text was...
Read more >scala - AbstractMethodError when mixing in trait nested in object
When I put the code in a file, compile it with scalac , and then use the compiled class files from the REPL...
Read more >Scala trait examples and syntax | alvinalexander.com
You can use Scala traits like abstract classes in Java. In the following example, an implementation is provided for the speak method in...
Read more >Abstract Type Members | Tour of Scala
Abstract types, such as traits and abstract classes, can in turn have abstract type members. ... trait Buffer: type T val element: T....
Read more >Scala Trait and Abstract Class - Commit Logs
In Scala, abstract class and trait can both be used as interface to define properties for extending classes to implement.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t sound like a binary compatible change, so not something we can do in scala 3.
This issue was picked for the Issue Spree 15 of May 3rd which takes place a week from now. @gagandeepkalra and @ghostbuster91 will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.