frellan
04/03/2018, 5:55 AMconstructor(
title: String,
portions: Int,
sections: List<ClassA>,
sourceUrl: String? = null
)
and this:
constructor(
title: String,
portions: Int,
ingredients: List<ClassB>,
sourceUrl: String? = null
)
Apperently have the same JVM signature, why is that? Can’t it see that ClassA
and ClassB
are two different classes in the list? I did not know that two lists with different content looked the same to the bytecodeAlexander Mikhalchenko
04/03/2018, 6:11 AMfrellan
04/03/2018, 6:27 AMfrellan
04/03/2018, 6:28 AMgildor
04/03/2018, 6:31 AMfrellan
04/03/2018, 6:37 AMgildor
04/03/2018, 6:44 AMfrellan
04/03/2018, 6:46 AMgildor
04/03/2018, 6:48 AMfrellan
04/03/2018, 6:58 AMdiesieben07
04/03/2018, 7:20 AM@JvmName
in Kotlin to work around this.
Then you could use a "fake constructor", i.e. operator fun invoke
in companion object
and voila 🙂diesieben07
04/03/2018, 7:20 AMclass Foo {
companion object {
operator fun invoke(a: List<String>): Foo = TODO()
@JvmName("createFromIntList")
operator fun invoke(b: List<Int>): Foo = TODO()
}
}