Issue with ImmutablePair after upgrading Apache Commons Lang3 version

62 views Asked by At

I am facing an issue with my code since upgrading the lang3 version from 2.12.0 to 2.12.13

ImmutablePair(it, action).apply { className.invoke(this) }

It was working fine before but after the update, it states

"Not enough information to infer type variable T".

Is there any reason for this?

I turned it back to the old version since it broke the code

1

There are 1 answers

0
AndrewL On
  1. I think your version numbers are wrong. Commons Lang 3 version numbers start with 3.x see Change Report.
  2. It would see from this Java doc, that a new method called apply was introduced in v3.13.0 to "Applies this key and value as arguments to the given function."
  3. Because the underlying class now has an apply() method you cannot use Kotlin's apply. So the behaviour you see is not a Kotlin defect, but you are unwittingly using a totally different method from Apache Commons.
  4. Remedy 1: You could use run { }, let { }, etc instead of apply { }
  5. Remedy 2: Overall, what are you are you trying to achieve with ImmutablePair that cannot be achieve with Kotlin's native Pair class (which is immutable)? Consider changing to that!

You do not state what the object className is. Perhaps there is something else relevant with that.