a member function reference `JSONObject::put` is p...
# announcements
a
a member function reference
JSONObject::put
is passed to a function that has generics but the type inference can’t decide between two methods that it thinks could be possible. (Boolean or Any, although passed type is Boolean in another parameter as T? and in function reference signature as T)
Copy code
inline fun <T : Any> JSONObject.putNullable(key: String,
                                            value: T?,
                                            write: JSONObject.(String, T) -> JSONObject) =
        if (value == null) put(key, JSONObject.NULL) else write(key, value)

fun JSONObject.putNullableBoolean(key: String, value: Boolean?) = putNullable(key, value, JSONObject::put)
with overloads for the reference
JSONObject::put
Copy code
public JSONObject put(String name, boolean value) throws JSONException
public JSONObject put(String name, double value) throws JSONException
public JSONObject put(String name, int value) throws JSONException
public JSONObject put(String name, long value) throws JSONException
public JSONObject put(String name, Object value) throws JSONException