https://kotlinlang.org logo
Title
s

Steve

12/02/2019, 8:20 PM
does Kotlin have some kind of index type? for example, I want to pass a List, and an index into that List. I could pass just an Int as the index, but it's possible that is outside the bounds of the list. I was wondering if there was some kind of type-safe way to tie the two together?
🇳🇴 1
🆗 1
h

Holger Steinhauer [Mod]

12/02/2019, 8:35 PM
Hmm, sounds like a job for a
List
? They are indexed by nature and if you need “empty” places, allow `null`able types.
Or do I miss something?
s

Steve

12/02/2019, 8:37 PM
that's not quite what I want. Normally I'd pass just the sublist that I'm interested in, or just the element, but in this case, I need to know where in the list I am, and have access to the whole list
l

Luke

12/02/2019, 8:37 PM
You might be interested in
list.getOrNull(index)
. It returns null if the index in out of bounds
👍 1
s

Steve

12/02/2019, 8:38 PM
yeah, that seems like what I need. Thanks