--Kotlin is a language that runs on the JVM created by JetBrains. --Kotlin is fully interoperable with Java. You can write a class in Java, a class that inherits it in Kotlin, and an inherited class in Java. --You can write additional developments in Kotlin for a project written in Java, which makes it easy to introduce.
Java
String str = "aaa";
Kotlin
var str: String = "aaa"
Use val to declare final variables and var to declare mutable variables.
Java
String foo = bar < 10 ? "abc" : "xyz";
Kotlin
var foo = if (bar < 10) "abc" else "xyz"
You can directly assign the result in an if or else block.
Java
for (int num : numbers) {
System.out.println(num);
}
for (int i = 0; i< 5; i++) {
System.out.println(i);
}
Kotlin
for (num in numbers) {
println(num)
}
for (i in 0 until 5) {
println(i)
}
kotlin uses in.
Java
Foo foo = new Foo();
Kotlin
var foo = Foo()
In kotlin, new is not needed.
Recommended Posts