Migrating Tuples (Kotlin M3 and Higher)

Tuple types and expression are no longer supported in Kotlin starting from M3. Data classes are the preferred way of dealing with tuple-like data. Library classes Pair and Triple are available for respective purposes.

If you have some code that uses tuples, written in earlier versions of Kotlin, you can migrate automatically using a quick-fix available in IntelliJ IDEA plugin for Kotlin, version M3.

Tuple types and expressions will be highlighted as errors in your code, a quick-fix is available on the errors for tuples of length 0 through 3:

After applying the quick-fix all tuples in your project will be migrated, and their usages, too. For example pairs will be replaced by usages of class Pair:

Tuples longer than tree do not have library analogs, so the quick-fix does not change them. As the error message suggests, use hand-written data classes:

Creating a data class takes only one line of code and makes reading easier with (supposedly) meaningful names:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">