class CollisionOfTanks(val Ob1:InterfaceIObject, val Ob2:InterfaceIObject, val map:HashMap<Int,HashMap<Int,HashMap<Int,Int>>>) val collision = map.getOrDefault(1 to hashMapOf(direction1 to hashMapOf(coordinates1[0] to coordinates1[1])), 42) 

Gives an error message

Type inference failed. The value of the parameter should be referred to as the type, receiver type or expected type. Try to specify it explicitly.

I tried to specify a type like this:

  val collision = map.getOrDefault<HashMap<Int,HashMap<Int,HashMap<Int,Int>>>, Int>(1 to hashMapOf(direction1 to hashMapOf(coordinates1[0] to coordinates1[1])), 42) 

But then it writes in general

GetOrDefault (key: Int, defaultValue: HashMap>): HashMap>

How to fix it? Or replace? I just need to know if there is any value for this key.

    1 answer 1

     val map: Map<Int, Map<Int, Map<Int, Int>>> = mapOf() val result = map.get(10)?.get(20)?.get(30) ?: 42 assertEquals(42, result) 

    If no key is found in the chain, it will return 42.