0

While converting from java to kotlin the output is given as follows Java:

Gson gson = new Gson();
    String strObj = getIntent().getStringExtra("passdata");
    userDictionery  = gson.fromJson(strObj, Map.class);

Kotlin:

val gson = Gson()
    val strObj = intent.getStringExtra("passdata")
    userDictionery = gson.fromJson<Map<*, *>>(strObj, Map<*, *>::class.java) as Map<String, String>?

But second line in kotlin shows an error that - Only Classes are allowed left hand side of the class literal

variable userDictionery is declared as Map<String, String>

How to resolve this issue?

1 Answer 1

1

You can't reference classes with their generic parameters in Kotlin the same way you can't reference them in java. So Map<*, *>::class is in the same way invalid in Kotlin as Map<?, ?>.class is in Java. Replace this:

gson.fromJson<Map<*, *>>(strObj, Map<*, *>::class.java)

With that:

gson.fromJson<Map<*, *>>(strObj, Map::class.java)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for support. I've updated code with non null check also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.