Kotlin is bypassing all other JVM languages with incredible pace. In Android development, it is already the language to use! But Java also evolved in meantime. Let’s look at Kotlin and compare its features side by side.
What is the principal JVM language you use for your main applications? • Kotlin edges past Groovy and Scala in language usage on 2.42% https://snyk.io/blog/jvm-ecosystem-report-2018/
in Kotlin are compiled into JVM primitives where possible. • Compiler decides • Works because of missing widening int a = 1; double b = a; val a:Int = 1 val b:Double = a
a.dec() + see below Expression Translated to +a a.unaryPlus() -a a.unaryMinus() !a a.not() Expression Translated to a + b a.plus(b) a - b a.minus(b) a * b a.times(b) a / b a.div(b) a % b a.rem(b), a.mod(b) (deprecated) a..b a.rangeTo(b)
> 0 a < b a.compareTo(b) < 0 a >= b a.compareTo(b) >= 0 a <= b a.compareTo(b) <= 0 Expression Translated to a == b a?.equals(b) ?: (b === null) a != b !(a?.equals(b) ?: (b === null))
a !in b !b.contains(a) Expression Translated to a[i] a.get(i) a[i, j] a.get(i, j) a[i_1, ..., i_n] a.get(i_1, ..., i_n) a[i] = b a.set(i, b) a[i, j] = b a.set(i, j, b) a[i_1, ..., i_n] = b a.set(i_1, ..., i_n, b)
a(i, j) a.invoke(i, j) a(i_1, ..., i_n) a.invoke(i_1, ..., i_n) Expression Translated to a += b a.plusAssign(b) a -= b a.minusAssign(b) a *= b a.timesAssign(b) a /= b a.divAssign(b) a %= b a.remAssign(b), a.modAssign(b) (deprecated)
final by default (vs open) • Inner class: static by default (vs inner) • Stricter usage of protected • New visibility: internal • One file can have multiple public classes
final by default (vs open) • Inner class: static by default (vs inner) • Stricter usage of protected • New visibility: internal • One file can have multiple public classes • „global“ functions & variables are allowed
final by default (vs open) • Inner class: static by default (vs inner) • Stricter usage of protected • New visibility: internal • One file can have multiple public classes • „global“ functions & variables are allowed • No checked Exceptions
in the lines of code by approximately 40 % (JetBrains) … tests show … the number of code lines reduces by 30… https://belitsoft.com/apps-development-services/java-vs-kotlin
its null-handling) but feels like a very careful amalgamation of some of the best features of other languages. Rob Fletcher, Netflix https://belitsoft.com/apps-development-services/java-vs-kotlin