zeugederunity
10/06/2020, 9:41 AMscala.Function1
i recognized that Kotlin has problems with overriding traits.
If you use it as functional interface, you get a Kotlin: Interface Function1 does not have constructors
error:
ScalaFunction1<Any, String> {
('A'.toInt()+(it as Int)).toChar().toString()
}
If you implement it as anonymous object you get the error Kotlin: Object is not abstract and does not implement abstract member public abstract fun <A : Any!> compose(p0: Function1<A!, Any!>!): Function1<A!, String!>! defined in scala.Function1
:
private fun tabulateIntToStringFunc() = object : ScalaFunction1<Any, String> {
override fun apply(v1: Any?): String {
return ('A'.toInt()+(v1 as Int)).toChar().toString()
}
}
If you implement andThen
and compose
you get the error `Kotlin: Object is not abstract and does not implement abstract member public abstract fun `apply$mcZD$sp`(p0: Double): Boolean defined in scala.Function1` :
private fun tabulateIntToStringFunc() = object : ScalaFunction1<Any, String> {
override fun apply(v1: Any?): String {
return ('A'.toInt()+(v1 as Int)).toChar().toString()
}
override fun <A : Any?> andThen(g: scala.Function1<String, A>?): scala.Function1<Any, A> {
throw NotImplementedError()
}
override fun <A : Any?> compose(g: scala.Function1<A, Any>?): scala.Function1<A, String> {
throw NotImplementedError()
}
}
But it is not possible to override this abstract function.
Can someone explain to me what is happening there? I'm new to this Scala-Kotlin business, i think this lack of knowledge is my core-problem here. Furthermore i don't know the inner working mechanisms of Scala and its java-interop, which adds even more challenges for me. ^^'scala.runtime.AbstractFunctionN
, allowing to use FunctionN
. But i don't get, why there are these "ghost functions" when implementing a trait.asm0dey
04/09/2021, 10:26 AM