![]() In its simplest form, it looks as follows:Ībove is a type for a function that takes no parameter and returns a Unit (void in other language parlance)Ībove is a type for a function that takes no parameter and return a StringĪbove is a type for a function that takes a string and returns nothing.Ībove is a type for a function that takes two parameters (String and Float) and returns nothing.īecause a function type is just a type, it means that you can assign it to a variable, you can pass it as a function argument and you can return it from a function. ![]() ![]() Function Types and Function LiteralsĪ function type is a type consisted of a function signature and function return type that are separated by -> operator. Since vararg creates an array, you simply use the * operator to pass one vararg to another. "$firstName $lastName" for simple variable name or "$ ") Kotlin has string templates, which is awesome.So there is no need to stuff your functions as static members of classes like what you do in C# or Java. Like JavaScript, you can create functions outside classes.Unlike Java, you do not need to match your file name to your class name.Comments are similar to Java or C#, /* This is comment */ for multi line comments and // for single line comment.Kotlin project website is at .Īll the codes here can be copied and run on Kotlin online editor. The latest version of the language is Kotlin M5.3 It produces Java bytecode, supports Android and generates JavaScript. Kotlin is a new programming language for the JVM.
0 Comments
Leave a Reply. |