Jörn Horstmann
Jörn Horstmann

Reputation: 34024

Avoiding deprecation warning when using FastUtil IntList from Kotlin

FastUtil contains optimized collection implementations that avoid autoboxing overhead. To notify programmers of unintended autoboxing, for example when using IntList, they marked the Integer get(int) method as deprecated, suggesting to use int getInt(int) instead. this leads to a deprecation warning when using the array index syntax with such lists:

import it.unimi.dsi.fastutil.ints.IntArrayList

private fun test() {
    val list = IntArrayList(listOf(1, 2, 3))
    println(list[0]) // deprecation warning on this line
}

I tried redefining get as an operator function, but this does not seem to work because of "Extension is shadowed by a memeber".

operator fun IntArrayList.get(i: Int): Int {
    return this.getInt(i)
}

Is there any other way to use array index syntax without deprecation warning and without suppressing all other deprecations?

Upvotes: 1

Views: 279

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170805

No, I don't believe there is. You could write a wrapper which would be a non-trivial amount of work.

Other primitive collection libraries don't necessarily have this problem, e.g. Trove's TIntList can use int get(int offset) because it doesn't extend List<Integer>. Same for HPPC.

Upvotes: 1

Related Questions