Eric Obermuhlner
06/04/2019, 6:30 AMabstract class A<T> {
abstract fun broken(vararg values: T): T
}
// Error: Class 'B' is not abstract and does not implement abstract base class member public abstract fun broken(vararg values: Int): Int defined in A
// Error: 'broken' overrides nothing
class B : A<Int>() {
override fun broken(vararg values: Int): Int {
return 5
}
}
The same code works fine if the subclass is with a "normal" object and not a primitive type.
Actually the IntelliJ IDE also thinks it should work, at least it generates the code for it but the compiler then complains about it.
Tested with kotlin 1.3.31Pavlo Liapota
06/04/2019, 7:54 AMA
expects method that accepts Array<Int>
(or Integer[]
) while class B
has IntArray
(or int[]
).Eric Obermuhlner
06/04/2019, 8:31 AMEric Obermuhlner
06/04/2019, 8:33 AMabstract class A<T> {
abstract fun broken(vararg values: T): String
}
class B : A<Int>() {
override fun broken(values: Array<out Int>): String {
return broken(*values.toIntArray())
}
fun broken(vararg values: Int): String {
return values.joinToString { it.toString() }
}
}
Unfortunately it pollutes class B
with another visible method broken(values: Array<out Int>)
.
If the bug ever gets fixed the workaround will lead to a syntax error.
Any better ideas?