Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinoperator overloadingSingle-choice MCQ

What is the result of this operator-overloaded `get`/`set` usage, and why?

class Grid { private val cells = HashMap<Pair<Int, Int>, Int>() operator fun get(x: Int, y: Int): Int = cells[x to y] ?: 0 operator fun set(x: Int, y: Int, value: Int) { cells[x to y] = value } } val g = Grid() g[1, 2] = 9 val v = g[1, 2]