I'm using GSON to get some simple value, which can...
# announcements
r
I'm using GSON to get some simple value, which can be converted to int, double, string, etc. And i tried to make the function generic. Below is my codes, the 'when' part is something i would like to do in kotlin. But i don't know how to use the subtype T in 'when'.
Copy code
inline fun <reified T> optionalScalarValue(jsonObject: JsonObject, field: String): T? {
        val element = jsonObject.get(field)

        when(T) {
            is Double -> return element.asDouble
        }
    }