Kotlin vs Java

Default and non-null parameters
Java
public void hello(String name) {
  if (name == null) {
    name = "World";
  }

  System.out.print("Hello, " + name + "!");
}
Kotlin
fun hello(name: String = "World") {
    println("Hello, $name!")
}
Single-statement functions
Java
public double cube(double x) {
  return x * x * x;
}
Kotlin
fun cube(x: Double) : Double = x * x * x
Vararg
Java
public int sum(int... numbers) { }
Kotlin
fun sum(vararg x: Int) { }
Public functions
Java
public class Main {
    public static void main(final String[] args){
        openFile("file.txt", true);
    }
}

class FileUtils {
    public static File openFile(String filename, boolean readOnly) { }
}
Kotlin
fun main() {
  openFile("file.txt", true)
}

fun openFile(filename: String, readOnly: Boolean) : File { }
Default parameters
Java
public static void main(String[]args){
  createFile("file.txt");

  createFile("file.txt", true);

  createFile("file.txt", true, false);

  createExecutableFile("file.txt");
}

public static File createFile(String filename) { }

public static File createFile(String filename, boolean appendDate) { }

public static File createFile(String filename, boolean appendDate,
                              boolean executable) { }

public static File createExecutableFile(String filename) { }
Kotlin
fun main(args: Array<String>) {
  createFile("file.txt")

  createFile("file.txt", true)
  createFile("file.txt", appendDate = true)

  createFile("file.txt", true, false)
  createFile("file.txt", appendDate = true, executable = true)

  createFile("file.txt", executable = true)
}

fun createFile(filename: String, appendDate: Boolean = false,
               executable: Boolean = false): File { }
Generic methods
Java
public void init() {
  var moduleInferred = createList("net");
}

public <T> List<T> createList(T item) { }
Kotlin
fun init() {
  val module = createList<String>("net")
  val moduleInferred = createList("net")
}

fun <T> createList(item: T): List<T> { }
Data classes
Java
public static void main(String[]args) {
    val book = createBook();
    System.out.println(book);
    System.out.println("Title: " + book.title);
}

public static Book createBook(){
    return new Book("title_01", "author_01");
}

@Data // Lombok
public class Book {
    private final String title;
    private final String author;
}
Kotlin
fun main(args: Array<String>) {
    val book = createBook();
    // or
    val (title, author) = createBook()

    println(book)
    println("Title: $title")
}

fun createBook() : Book{
    return Book("title_01", "author_01")
}

data class Book(val title: String, val author: String)