Kotlin migration
Recipes for migrating to newer Kotlin versions.
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
- Migrate to Kotlin 2
- Migrate to Kotlin 2.x
- Migrate to
kotlinx-datetime0.7 - Remove redundant
@OptInannotations - Remove redundant kotlin-stdlib dependencies
- Replace deprecated Char case conversions
- Replace deprecated String case conversions
- Replace deprecated
capitalizeanddecapitalize - Upgrade to
kotlinx-coroutines1.10 - Upgrade to
kotlinx-serialization1.8 - Use
Charextensions instead ofjava.lang.Character - Use Kotlin array extensions instead of
java.util.Arrays - Use Kotlin collection extensions instead of
java.util.Collections - Use Kotlin number extensions instead of
java.lang.Integer/Long/Double/Float/Boolean - Use
kotlin.mathinstead ofjava.lang.Math - Use
kotlin.text.Regexinstead ofjava.util.regex.Pattern - Use modern Kotlin stdlib idioms
Recipes
- Remove deprecated Kotlin Gradle properties
- Replace
Enum.values()withEnum.entries - Replace deprecated
appendlnwithappendLine - Replace
enumValues<T>()withenumEntries<T>() - Replace
kotlinOptionswithcompilerOptionsin Gradle build files - Upgrade Kotlin Gradle plugins to 2.x
- Use
..<instead ofuntil - Use
@JvmInline value classinstead ofinline class - Use
Array.contentDeepEquals()instead ofArrays.deepEquals(a, b) - Use
Array.contentDeepHashCode()instead ofArrays.deepHashCode(arr) - Use
Array.contentDeepToString()instead ofArrays.deepToString(arr) - Use
Array.contentEquals()instead ofArrays.equals(a, b) - Use
Array.contentHashCode()instead ofArrays.hashCode(arr) - Use
Array.contentToString()instead ofArrays.toString(arr) - Use
BooleanArray.contentEquals()instead ofArrays.equals(a, b) - Use
BooleanArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
BooleanArray.contentToString()instead ofArrays.toString(arr) - Use
BooleanArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
BooleanArray.fill()instead ofArrays.fill(arr, value) - Use
ByteArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
ByteArray.contentEquals()instead ofArrays.equals(a, b) - Use
ByteArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
ByteArray.contentToString()instead ofArrays.toString(arr) - Use
ByteArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
ByteArray.decodeToString()instead ofString(byteArray) - Use
ByteArray.fill()instead ofArrays.fill(arr, value) - Use
ByteArray.sort()instead ofArrays.sort(arr) - Use
Char(int)instead ofInt.toChar() - Use
Char.codeinstead ofChar.toInt() - Use
Char.code.toByte()instead ofChar.toByte() - Use
Char.code.toDouble()instead ofChar.toDouble() - Use
Char.code.toFloat()instead ofChar.toFloat() - Use
Char.code.toLong()instead ofChar.toLong() - Use
Char.code.toShort()instead ofChar.toShort() - Use
Char.compareToinstead ofjava.lang.Character.compare - Use
Char.digitToInt(radix)instead ofCharacter.digit(c, radix) - Use
Char.isDefined()instead ofCharacter.isDefined(c) - Use
Char.isDigit()instead ofCharacter.isDigit(c) - Use
Char.isHighSurrogate()instead ofCharacter.isHighSurrogate(c) - Use
Char.isISOControl()instead ofCharacter.isISOControl(c) - Use
Char.isLetter()instead ofCharacter.isLetter(c) - Use
Char.isLetterOrDigit()instead ofCharacter.isLetterOrDigit(c) - Use
Char.isLowSurrogate()instead ofCharacter.isLowSurrogate(c) - Use
Char.isLowerCase()instead ofCharacter.isLowerCase(c) - Use
Char.isTitleCase()instead ofCharacter.isTitleCase(c) - Use
Char.isUpperCase()instead ofCharacter.isUpperCase(c) - Use
Char.isWhitespace()instead ofCharacter.isWhitespace(c) - Use
Char.lowercaseChar()instead ofChar.toLowerCase() - Use
Char.lowercaseChar()instead ofCharacter.toLowerCase(c) - Use
Char.toString()instead ofCharacter.toString(c) - Use
Char.uppercaseChar()instead ofChar.toUpperCase() - Use
Char.uppercaseChar()instead ofCharacter.toUpperCase(c) - Use
CharArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
CharArray.concatToString()instead ofString(charArray) - Use
CharArray.contentEquals()instead ofArrays.equals(a, b) - Use
CharArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
CharArray.contentToString()instead ofArrays.toString(arr) - Use
CharArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
CharArray.fill()instead ofArrays.fill(arr, value) - Use
CharArray.sort()instead ofArrays.sort(arr) - Use
Collection.max()instead ofCollections.max(coll) - Use
Collection.min()instead ofCollections.min(coll) - Use
Double.IEEEreminstead ofjava.lang.Math.IEEEremainder - Use
Double.nextDown()instead ofjava.lang.Math.nextDown - Use
Double.nextTowards()instead ofjava.lang.Math.nextAfter - Use
Double.nextUp()instead ofjava.lang.Math.nextUp - Use
Double.powinstead ofjava.lang.Math.pow - Use
Double.roundToLong()instead ofjava.lang.Math.round - Use
Double.withSigninstead ofjava.lang.Math.copySign - Use
DoubleArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
DoubleArray.contentEquals()instead ofArrays.equals(a, b) - Use
DoubleArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
DoubleArray.contentToString()instead ofArrays.toString(arr) - Use
DoubleArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
DoubleArray.fill()instead ofArrays.fill(arr, value) - Use
DoubleArray.sort()instead ofArrays.sort(arr) - Use
Float.roundToInt()instead ofjava.lang.Math.round - Use
FloatArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
FloatArray.contentEquals()instead ofArrays.equals(a, b) - Use
FloatArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
FloatArray.contentToString()instead ofArrays.toString(arr) - Use
FloatArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
FloatArray.fill()instead ofArrays.fill(arr, value) - Use
FloatArray.sort()instead ofArrays.sort(arr) - Use
Int.MAX_VALUEinstead ofjava.lang.Integer.MAX_VALUE - Use
Int.MIN_VALUEinstead ofjava.lang.Integer.MIN_VALUE - Use
Int.compareToinstead ofjava.lang.Integer.compare - Use
Int.countLeadingZeroBits()instead ofInteger.numberOfLeadingZeros - Use
Int.countOneBits()instead ofjava.lang.Integer.bitCount - Use
Int.countTrailingZeroBits()instead ofInteger.numberOfTrailingZeros - Use
Int.digitToChar(radix)instead ofCharacter.forDigit(digit, radix) - Use
Int.floorDivinstead ofjava.lang.Math.floorDiv - Use
Int.mod()instead ofjava.lang.Math.floorMod - Use
Int.rotateLeft(n)instead ofInteger.rotateLeft(i, n) - Use
Int.rotateRight(n)instead ofInteger.rotateRight(i, n) - Use
Int.toString()instead ofInteger.toString(i) - Use
Int.toString(16)instead ofInteger.toHexString - Use
Int.toString(2)instead ofInteger.toBinaryString - Use
Int.toString(8)instead ofInteger.toOctalString - Use
Int.toString(radix)instead ofInteger.toString(i, radix) - Use
IntArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
IntArray.contentEquals()instead ofArrays.equals(a, b) - Use
IntArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
IntArray.contentToString()instead ofArrays.toString(arr) - Use
IntArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
IntArray.fill()instead ofArrays.fill(arr, value) - Use
IntArray.sort()instead ofArrays.sort(arr) - Use
Long.countOneBits()instead ofjava.lang.Long.bitCount - Use
Long.floorDivinstead ofjava.lang.Math.floorDiv - Use
Long.mod()instead ofjava.lang.Math.floorMod - Use
Long.mod(Int)instead ofjava.lang.Math.floorMod - Use
Long.rotateLeft(n)instead ofLong.rotateLeft(l, n) - Use
Long.rotateRight(n)instead ofLong.rotateRight(l, n) - Use
Long.toString()instead ofLong.toString(l) - Use
Long.toString(radix)instead ofLong.toString(l, radix) - Use
LongArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
LongArray.contentEquals()instead ofArrays.equals(a, b) - Use
LongArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
LongArray.contentToString()instead ofArrays.toString(arr) - Use
LongArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
LongArray.fill()instead ofArrays.fill(arr, value) - Use
LongArray.sort()instead ofArrays.sort(arr) - Use
MutableList.reverse()instead ofCollections.reverse(list) - Use
MutableList.shuffle()instead ofCollections.shuffle(list) - Use
MutableList.sort()instead ofCollections.sort(list) - Use
Regex.escape(s)instead ofPattern.quote(s) - Use
ShortArray.binarySearch()instead ofArrays.binarySearch(arr, key) - Use
ShortArray.contentEquals()instead ofArrays.equals(a, b) - Use
ShortArray.contentHashCode()instead ofArrays.hashCode(arr) - Use
ShortArray.contentToString()instead ofArrays.toString(arr) - Use
ShortArray.copyOf()instead ofArrays.copyOf(arr, newLength) - Use
ShortArray.fill()instead ofArrays.fill(arr, value) - Use
ShortArray.sort()instead ofArrays.sort(arr) - Use
String.toBoolean()instead ofjava.lang.Boolean.parseBoolean(s) - Use
String.toDouble()instead ofjava.lang.Double.parseDouble(s) - Use
String.toFloat()instead ofjava.lang.Float.parseFloat(s) - Use
String.toInt()instead ofInteger.parseInt(s) - Use
String.toInt(radix)instead ofInteger.parseInt(s, radix) - Use
String.toLong()instead ofjava.lang.Long.parseLong(s) - Use
String.toLong(radix)instead ofLong.parseLong(s, radix) - Use
String.toRegex()instead ofPattern.compile(s) - Use
Throwable.localizedMessageinstead ofThrowable.message - Use
appendLine()instead ofappendln() - Use
appendLine(char)instead ofappendln(char) - Use
appendLine(cs)instead ofappendln(cs)(CharSequence) - Use
appendLine(value)instead ofappendln(value) - Use
appendLine(value)instead ofappendln(value)(Any?) - Use
enumEntries<T>()instead ofenumValues<T>() - Use
kotlin.math.Einstead ofjava.lang.Math.E - Use
kotlin.math.PIinstead ofjava.lang.Math.PI - Use
kotlin.math.absinstead ofjava.lang.Math.abs - Use
kotlin.math.acosinstead ofjava.lang.Math.acos - Use
kotlin.math.asininstead ofjava.lang.Math.asin - Use
kotlin.math.ataninstead ofjava.lang.Math.atan - Use
kotlin.math.atan2instead ofjava.lang.Math.atan2 - Use
kotlin.math.cbrtinstead ofjava.lang.Math.cbrt - Use
kotlin.math.ceilinstead ofjava.lang.Math.ceil - Use
kotlin.math.cosinstead ofjava.lang.Math.cos - Use
kotlin.math.coshinstead ofjava.lang.Math.cosh - Use
kotlin.math.expinstead ofjava.lang.Math.exp - Use
kotlin.math.expm1instead ofjava.lang.Math.expm1 - Use
kotlin.math.floorinstead ofjava.lang.Math.floor - Use
kotlin.math.hypotinstead ofjava.lang.Math.hypot - Use
kotlin.math.lninstead ofjava.lang.Math.log - Use
kotlin.math.ln1pinstead ofjava.lang.Math.log1p - Use
kotlin.math.log10instead ofjava.lang.Math.log10 - Use
kotlin.math.maxinstead ofjava.lang.Math.max - Use
kotlin.math.mininstead ofjava.lang.Math.min - Use
kotlin.math.signinstead ofjava.lang.Math.signum - Use
kotlin.math.sininstead ofjava.lang.Math.sin - Use
kotlin.math.sinhinstead ofjava.lang.Math.sinh - Use
kotlin.math.sqrtinstead ofjava.lang.Math.sqrt - Use
kotlin.math.taninstead ofjava.lang.Math.tan - Use
kotlin.math.tanhinstead ofjava.lang.Math.tanh - Use
listOf(x)instead ofCollections.singletonList(x) - Use
lowercase()instead oftoLowerCase() - Use
lowercase(locale)instead oftoLowerCase(locale) - Use
readln()instead ofreadLine()!! - Use
readlnOrNull()instead ofreadLine() - Use
removeAt(0)instead ofremoveFirst() - Use
removeAt(lastIndex)instead ofremoveLast() - Use
replaceFirstChar \{ it.lowercase() \}instead ofdecapitalize() - Use
replaceFirstChar \{ … \}instead ofcapitalize() - Use
setOf(x)instead ofCollections.singleton(x) - Use
sumOfinstead ofsumBy - Use
sumOfinstead ofsumByDouble - Use
uppercase()instead oftoUpperCase() - Use
uppercase(locale)instead oftoUpperCase(locale)