I have the following class:
class Entry1(var type:String, var kind:String, var index:Int)
And a map:
var map1 = mutableMapOf<String, Entry>()
How would I access the attributes of Entry1 of a given map entry?
Example: Say I have:
map1["ex1"] = Entry("ex2","ex3",4)
Now I want to get the index
from the Entry I've added.
How can that be done?
答案 0 :(得分:0)
val entry = map1["ex1"]
if (entry != null) {
val index = entry.index;
...
}
答案 1 :(得分:0)
或
val entry = map1["ex1"]
val index = entry?.let{
entry.index
} ?: -1 //optional