fun hello() { println("Hello, World!") }
Java
public void hello(){ System.out.print("Hello, World!"); }
fun hello(name:String) { println("Hello,$name!") }
Java
public void hello(String name){ System.out.print("Hello, " + name + "!"); }
fun hello(name:String="World") { println("Hello,$name!") }
Java
public void hello(String name){ if (name == null) { name = "World"; } System.out.print("Hello, " + name + "!"); }
fun hasItems() : Boolean { return true }
Java
public boolean hasItems(){ return true; }
fun cube(x:Double) : Double = x * x * x
Java
public double cube(double x){ return x * x * x; }
fun sum(vararg x: Int) { }
Java
public int sum(int... numbers){ }
fun main(args:Array<String>) { }
Java
public class MyClass{ public static void main(String[] args){ } }
fun main(args:Array<String>) { openFile("file.txt", readOnly = true) } fun openFile(filename:String, readOnly:Boolean) : File { }
Java
public static void main(String[]args){ openFile("file.txt", true); } public static File openFile(String filename,boolean readOnly){ }
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 { }
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){ }
fun init() { val module = createList<String>("net") val moduleInferred = createList("net") } fun <T>createList(item:T): List<T> { }
Java
public void init(){ List<String> moduleInferred = createList("net"); } public <T> List<T>createList(T item){ }