homchom
01/11/2023, 5:32 AMList.of
IntelliJ warns me that it "should be replaced with [the] Kotlin function" listOf
. If I understand correctly, these two functions are actually very different; is there something I am missing? Is this a false positive?ephemient
01/11/2023, 8:21 AMephemient
01/11/2023, 8:26 AMval x: MutableList<Int> = List.of()
whereas listOf()
would be rejectedCLOVIS
01/11/2023, 8:29 AMlistOf
. Someone running code in the same JVM as you will be able to edit any value if they really want to.ephemient
01/11/2023, 8:32 AMCollections.unmodifiableList()
etc. being used defensively if interoperating with Java code, and List.of()
is similar to unmodifiableList(listOf())
(with a few additional unique behaviors). if that really is your situation, then ignore the inspection. but if you're just in Kotlin, I would stick with the Kotlin functions.ephemient
01/11/2023, 8:49 AM