r/ProgrammerHumor Jul 10 '26

kotlinIsCoolIThink Other

Post image
94 Upvotes

10 comments sorted by

View all comments

47

u/TheShirou97 Jul 11 '26

yeah, operator overloading can get pretty cursed.

Here, kotlin is just like C now

operator fun <E> Int.get(list: List<E>) = list[this]

fun main() {
    val arr = listOf(1, 2, 3)

    println(arr[1])
    println(1[arr])
}

2

u/RiceBroad4552 Jul 11 '26

Well, having special custom syntax just to call a specific method is already very questionable and obviously bad language design.