https://kotlinlang.org logo
#klaxon
Title
# klaxon
b

Byron Woodfork

12/02/2019, 10:25 PM
Copy code
class ShapeTypeAdapter: TypeAdapter<Shape> {
    override fun classFor(type: Any): KClass<out Shape> = when(type as Int) {
        1 -> Rectangle::class
        2 -> Circle::class
        else -> throw IllegalArgumentException("Unknown type: $type")
    }
}
a

Animesh Sahu

12/03/2019, 4:08 PM
You can pass
{}
a lambda instead throwing an exception, for caching the exception you can do that whereever you parse the object
👍🏾 2
b

Byron Woodfork

12/03/2019, 9:13 PM
Thx!
3 Views