0

In Java, I am able to activate compiler warnings (even errors) for autoboxing. How can I achieve the same in Kotlin? Right now I often find myself decompiling the Kotlin bytecode to Java to double-check, which seems like a hassle.

I quickly skimmed through some static code analysis tools for Kotlin, but haven't found one that supports checking boxing events.

ndr
  • 21
  • 1
  • 2
  • 1
    Potential performance savings by avoiding using the primitives as generic types, because the compiler uses the primitive version without boxing whenever possible. That said, it's pretty easy to remember not to make a size 100,000 `List` if you're working with performance-critical code. No need for a compiler warning. – Tenfour04 May 23 '20 at 20:06
  • @Tenfour04 Unfortunately it's not that obvious as "not making a `List`". See [this](https://discuss.kotlinlang.org/t/kotlin-and-auto-boxing-of-parameters-and-result/1908) example. @Marvin Of course Kotlin uses primitive types. Why do you think there is an `IntArray` in the standard lib? – ndr May 23 '20 at 22:27
  • Well, it's generics and non-inlined lambdas, which compile as generic interfaces. – Tenfour04 May 23 '20 at 23:30
  • I am fully aware of that. But it's not always "pretty easy to remember" as you depicted the problem. Especially when you enter a large codebase which relies heavily on these implicit boxing events and your job is to get rid of them. – ndr May 24 '20 at 00:43
  • @ndr why not profile your code and only manually check for autoboxing in hot sections? – PiRocks May 24 '20 at 08:45
  • 1
    @PiRocks It's what I am doing, but I thought there was a tool that could assist me with the manual checking. Seems like I was wrong. – ndr May 25 '20 at 02:48

0 Answers0