I have a PreferencesManager written in Java with the following method:
public void insert(Pair<String, Object> keyValue, boolean async) {
And from kotlin I'm trying to insert a new Pair into the PreferencesManager like so:
val p = Pair(SharedPreferencesManager.STATIC_KEY, value)
preferencesManager!!.insert(p, false)
However i'm getting an error saying:
"Required android.util.Pair, found kotlin.Pair"...
Is there a way I can convert from one to the other?
As an alternative to the answer @TheWanderer gave in the comments of the question. I would suggest importing android.util.Pair using the as
keyword as follows:
import android.util.Pair as APair
//....
val p = APair(SharedPreferencesManager.STATIC_KEY, value)
preferencesManager!!.insert(p, false)
See the kotlin docs on importing for more. The kotlin package is always going to imported, and apparently will take precedence over classes from other packages unless you rename them or fully qualify them.
Kotlin has its own Pair, which isn't an extension or proxy for android.util.Pair
. Try using a helper method instead:
public void insert(String key Object value, boolean async) {
Pair<String, Object> pair = new Pair<>(key, value);
insert(pair, async);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With