From 1bec0f608977c00757c8f5732eedce2e57bb9bc3 Mon Sep 17 00:00:00 2001 From: s-webber Date: Sun, 13 Mar 2016 10:10:06 +0000 Subject: created kotlin markdown --- kotlin.html.markdown | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 kotlin.html.markdown (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown new file mode 100644 index 00000000..ae0123a7 --- /dev/null +++ b/kotlin.html.markdown @@ -0,0 +1,321 @@ +--- +language: kotlin +contributors: + - ["S Webber", "https://github.com/s-webber"] +filename: LearnKotlin.kt +--- + +Kotlin is a Statically typed programming language for the JVM, Android and the +browser. It is 100% interoperable with Java. +[Read more here.](https://kotlinlang.org/) + +```kotlin +// Single-line comments start with // +/* +Multi-line comments look like this. +*/ + +// The "package" keyword works in the same way as in Java. +package com.learnxinyminutes.kotlin + +/* +The entry point to a Kotlin program is a function named "main". +The function is passed an array containing any command line arguments. +*/ +fun main(args: Array) { + /* + Declaring values is done using either "var" or "val". + "val" declarations cannot be reassigned, whereas "vars" can. + */ + val fooVal = 10 // we cannot later reassign fooVal to something else + var fooVar = 10 + fooVar = 20 // fooVar can be reassigned + + /* + In most cases, Kotlin can determine what the type of a variable is, + so we don't have to explicitly specify it every time. + We can explicitly declare the type of a variable like so: + */ + val foo : Int = 7 + + /* + Strings can be represented in a similar way as in Java. + Escaping is done with a backslash. + */ + val fooString = "My String Is Here!"; + val barString = "Printing on a new line?\nNo Problem!"; + val bazString = "Do you want to add a tab?\tNo Problem!"; + println(fooString); + println(barString); + println(bazString); + + /* + A raw string is delimited by a triple quote ("""). + Raw strings can contain newlines and any other characters. + */ + val fooRawString = """ +fun helloWorld(val name : String) { + println("Hello, world!") +} +""" + println(fooRawString) + + /* + Strings can contain template expressions. + A template expression starts with a dollar sign ($). + */ + val fooTemplateString = "$fooString has ${fooString.length} characters" + println(fooTemplateString) + + /* + For a variable to hold null it must be explicitly specified as nullable. + A variable can be specified as nullable by appending a ? to its type. + We can access a nullable variable by using the ?. operator. + We can use the ?: operator to specify an alternative value to use + if a variable is null + */ + var fooNullable: String? = "abc" + println(fooNullable?.length) // => 3 + println(fooNullable?.length ?: -1) // => 3 + fooNullable = null + println(fooNullable?.length) // => null + println(fooNullable?.length ?: -1) // => -1 + + /* + Functions can be declared using the "fun" keyword. + Function arguments are specified in brackets after the function name. + Function arguments can optionally have a default value. + The function return type, if required, is specified after the arguments. + */ + fun hello(name: String = "world") : String { + return "Hello, $name!" + } + println(hello("foo")) // => Hello, foo! + println(hello(name = "bar")) // => Hello, bar! + println(hello()) // => Hello, world! + + /* + A function parameter may be marked with the "vararg" keyword + to allow a variable number of arguments to be passed to the function. + */ + fun varargExample(vararg names: Int) { + println("Argument has ${names.size} elements") + } + varargExample() // => Argument has 0 elements + varargExample(1) // => Argument has 1 elements + varargExample(1, 2, 3) // => Argument has 3 elements + + /* + When a function consists of a single expression then the curly brackets can + be omitted. The body is specified after a = symbol. + */ + fun odd(x: Int): Boolean = x % 2 == 1 + println(odd(6)) // => false + println(odd(7)) // => true + + // If the return type can be inferred then we don't need to specify it. + fun even(x: Int) = x % 2 == 0 + println(even(6)) // => true + println(even(7)) // => false + + // Functions can take functions as arguments and return functions. + fun not(f: (Int) -> Boolean) : (Int) -> Boolean { + return {n -> !f.invoke(n)} + } + // Named functions can be specified as arguments using the :: operator. + val notOdd = not(::odd) + val notEven = not(::even) + // Anonymous functions can be specified as arguments. + val notZero = not {n -> n == 0} + /* + If an anonymous function has only one parameter + then its declaration can be omitted (along with the ->). + The name of the single parameter will be "it". + */ + val notPositive = not {it > 0} + for (i in (0..4)) { + println("${notOdd(i)} ${notEven(i)} ${notZero(i)} ${notPositive(i)}") + } + + //The "class" keyword is used to declare classes. + class ExampleClass(val x: Int) { + fun memberFunction(y: Int) : Int { + return x + y + } + + infix fun infixMemberFunction(y: Int) : Int { + return x * y + } + } + /* + To create a new instance we call the constructor. + Note that Kotlin does not have a "new" keyword. + */ + val fooExampleClass = ExampleClass(7) + // Member functions can be called using dot notation. + println(fooExampleClass.memberFunction(4)) // => 11 + /* + If a function has been marked with the "infix" keyword then it can be + called using infix notation. + */ + println(fooExampleClass infixMemberFunction 4) // => 28 + + /* + Data classes are a concise way to create classes that just hold data. + The "hashCode"/"equals" and "toString" methods are automatically generated. + */ + data class DataClassExample (val x: Int, val y: Int, val z: Int) + val fooData = DataClassExample(1, 2, 4) + println(fooData) // => DataClassExample(x=1, y=2, z=4) + + // Data classes have a "copy" function. + val fooCopy = fooData.copy(y = 100) + println(fooCopy) // => DataClassExample(x=1, y=100, z=4) + + // Objects can be destructured into multiple variables. + val (a, b, c) = fooCopy + println("$a $b $c") // => 1 100 4 + + // The "with" function is similar to the JavaScript "with" statement. + data class MutableDataClassExample (var x: Int, var y: Int, var z: Int) + val fooMutableDate = MutableDataClassExample(7, 4, 9) + with (fooMutableDate) { + x -= 2 + y += 2 + z-- + } + println(fooMutableDate) // => MutableDataClassExample(x=5, y=6, z=8) + + /* + We can create a list using the "listOf" function. + The list will be immutable - elements cannot be added or removed. + */ + val fooList = listOf("a", "b", "c") + println(fooList.size) // => 3 + println(fooList.first()) // => a + println(fooList.last()) // => c + // elements can be accessed by index + println(fooList[1]) // => b + + // A mutable list can be created using the "mutableListOf" function. + val fooMutableList = mutableListOf("a", "b", "c") + fooMutableList.add("d") + println(fooMutableList.last()) // => d + println(fooMutableList.size) // => 4 + + // We can create a set using the "setOf" function. + val fooSet = setOf("a", "b", "c") + println(fooSet.contains("a")) // => true + println(fooSet.contains("z")) // => false + + // We can create a map using the "mapOf" function. + val fooMap = mapOf("a" to 8, "b" to 7, "c" to 9) + // Map values can be accessed by their key. + println(fooMap["a"]) // => 8 + + // Kotlin provides higher-order functions for working with collections. + val x = (1..9).map {it * 3} + .filter {it < 20} + .groupBy {it % 2 == 0} + .mapKeys {if (it.key) "even" else "odd"} + println(x) // => {odd=[3, 9, 15], even=[6, 12, 18]} + + // A "for" loop can be used with anything that provides an iterator. + for (c in "hello") { + println(c) + } + + // "while" loops work in the same way as other languages. + var ctr = 0 + while (ctr < 5) { + println(ctr) + ctr++ + } + do { + println(ctr) + ctr++ + } while (ctr < 10) + + // "when" can be used as an alternative to "if-else if" chains. + val i = 10 + when { + i < 7 -> println("first block") + fooString.startsWith("hello") -> println("second block") + else -> println("else block") + } + + // "when" can be used with an argument. + when (i) { + 0, 21 -> println("0 or 21") + in 1..20 -> println("in the range 1 to 20") + else -> println("none of the above") + } + + // "when" can be used as a function that returns a value. + var result = when (i) { + 0, 21 -> "0 or 21" + in 1..20 -> "in the range 1 to 20" + else -> "none of the above" + } + println(result) + + /* + We can check if an object is a particular type by using the "is" operator. + If an object passes a type check then it can be used as that type without + explicitly casting it. + */ + fun smartCastExample(x: Any) : Boolean { + if (x is Boolean) { + // x is automatically cast to Boolean + return x + } else if (x is Int) { + // x is automatically cast to Int + return x > 0 + } else if (x is String) { + // x is automatically cast to String + return x.isNotEmpty() + } else { + return false + } + } + println(smartCastExample("Hello, world!")) // => true + println(smartCastExample("")) // => false + println(smartCastExample(5)) // => true + println(smartCastExample(0)) // => false + println(smartCastExample(true)) // => true + + /* + Extensions are a way to add new functionality to a class. + This is similar to C# extension methods. + */ + fun String.remove(c: Char): String { + return this.filter {it != c} + } + println("Hello, world!".remove('l')) // => Heo, word! + + println(EnumExample.A) // => A + println(ObjectExample.hello()) // => hello +} + +// Enum classes are similar to Java enum types. +enum class EnumExample { + A, B, C +} + +/* +The "object" keyword can be used to create singleton objects. +We cannot assign it to a variable, but we can refer to it by its name. +This is similar to Scala singleton objects. +*/ +object ObjectExample { + fun hello() : String { + return "hello" + } +} + +``` + +### Further Reading + +A web-based mini-IDE for Kotlin: +[http://try.kotlinlang.org/) -- cgit v1.2.3 From f32379a55853db947c2512982d3979341119807f Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Tue, 15 Mar 2016 15:34:19 -0700 Subject: Set kotlin highlighting to java --- kotlin.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index ae0123a7..57f311f9 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -9,7 +9,7 @@ Kotlin is a Statically typed programming language for the JVM, Android and the browser. It is 100% interoperable with Java. [Read more here.](https://kotlinlang.org/) -```kotlin +```java // Single-line comments start with // /* Multi-line comments look like this. -- cgit v1.2.3 From f8f644d891ba8dede049e27f8ede47a060b74603 Mon Sep 17 00:00:00 2001 From: s-webber Date: Sat, 19 Mar 2016 10:06:54 +0000 Subject: removed unnecessary brackets --- kotlin.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index ae0123a7..47577906 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -133,7 +133,7 @@ fun helloWorld(val name : String) { The name of the single parameter will be "it". */ val notPositive = not {it > 0} - for (i in (0..4)) { + for (i in 0..4) { println("${notOdd(i)} ${notEven(i)} ${notZero(i)} ${notPositive(i)}") } -- cgit v1.2.3 From 9ccc431ea31f53040fd693384ddfeaa75e834fc9 Mon Sep 17 00:00:00 2001 From: s-webber Date: Sat, 19 Mar 2016 10:08:01 +0000 Subject: updated further reading section --- kotlin.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 47577906..72018f51 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -317,5 +317,6 @@ object ObjectExample { ### Further Reading -A web-based mini-IDE for Kotlin: -[http://try.kotlinlang.org/) +* [Kotlin tutorials](https://kotlinlang.org/docs/tutorials/) +* [Try Kotlin in your browser](http://try.kotlinlang.org/) +* [A list of Kotlin resources](http://kotlin.link/) -- cgit v1.2.3 From 19ac1e8eeb92115b1af90ea1aa9181a8f6d48211 Mon Sep 17 00:00:00 2001 From: s-webber Date: Sun, 26 Jun 2016 14:20:28 +0100 Subject: [kotlin/en] Add examples of sequences (#2214) * minor capitalization and punctuation changes * examples of sequences * corrected comment --- kotlin.html.markdown | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 7b1475a8..605b1a63 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -5,7 +5,7 @@ contributors: filename: LearnKotlin.kt --- -Kotlin is a Statically typed programming language for the JVM, Android and the +Kotlin is a statically typed programming language for the JVM, Android and the browser. It is 100% interoperable with Java. [Read more here.](https://kotlinlang.org/) @@ -72,7 +72,7 @@ fun helloWorld(val name : String) { A variable can be specified as nullable by appending a ? to its type. We can access a nullable variable by using the ?. operator. We can use the ?: operator to specify an alternative value to use - if a variable is null + if a variable is null. */ var fooNullable: String? = "abc" println(fooNullable?.length) // => 3 @@ -137,7 +137,7 @@ fun helloWorld(val name : String) { println("${notOdd(i)} ${notEven(i)} ${notZero(i)} ${notPositive(i)}") } - //The "class" keyword is used to declare classes. + // The "class" keyword is used to declare classes. class ExampleClass(val x: Int) { fun memberFunction(y: Int) : Int { return x + y @@ -194,7 +194,7 @@ fun helloWorld(val name : String) { println(fooList.size) // => 3 println(fooList.first()) // => a println(fooList.last()) // => c - // elements can be accessed by index + // Elements of a list can be accessed by their index. println(fooList[1]) // => b // A mutable list can be created using the "mutableListOf" function. @@ -213,12 +213,37 @@ fun helloWorld(val name : String) { // Map values can be accessed by their key. println(fooMap["a"]) // => 8 + /* + Sequences represent lazily-evaluated collections. + We can create a sequence using the "generateSequence" function. + */ + val fooSequence = generateSequence(1, {it + 1}) + val x = fooSequence.take(10).toList() + println(x) // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + // An example of using a sequence to generate Fibonacci numbers: + fun fibonacciSequence() : Sequence { + var a = 0L + var b = 1L + + fun next() : Long { + val result = a + b + a = b + b = result + return a + } + + return generateSequence(::next) + } + val y = fibonacciSequence().take(10).toList() + println(y) // => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] + // Kotlin provides higher-order functions for working with collections. - val x = (1..9).map {it * 3} + val z = (1..9).map {it * 3} .filter {it < 20} .groupBy {it % 2 == 0} .mapKeys {if (it.key) "even" else "odd"} - println(x) // => {odd=[3, 9, 15], even=[6, 12, 18]} + println(z) // => {odd=[3, 9, 15], even=[6, 12, 18]} // A "for" loop can be used with anything that provides an iterator. for (c in "hello") { -- cgit v1.2.3 From 161edb1f6e76a8451d2e74a8fb24d6874f7dab66 Mon Sep 17 00:00:00 2001 From: Paolo Furini Date: Mon, 12 Sep 2016 16:33:16 +0200 Subject: [kotlin/en] Add "if" usage as an expression (#2367) * [kotlin/en] Add "if" usage as a function * [kotlin/en] Change comment on "if" expression Rephrase the comment to use the term "expression" in place of "function" --- kotlin.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 605b1a63..00182d81 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -261,6 +261,14 @@ fun helloWorld(val name : String) { ctr++ } while (ctr < 10) + /* + "if" can be used as an expression that returns a value. + For this reason the ternary ?: operator is not needed in Kotlin. + */ + val num = 5 + val message = if (num % 2 == 0) "even" else "odd" + println("$num is $message") // => 5 is odd + // "when" can be used as an alternative to "if-else if" chains. val i = 10 when { -- cgit v1.2.3 From 2fa414912e2fd9bdcd8fd5aa6df59e70f24dac06 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Wed, 5 Oct 2016 13:27:41 +0300 Subject: [Kotlin/en] correct object clarification (#2413) * Kotlin: correct object clarification * Kotlin: correct object clarification --- kotlin.html.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 00182d81..4c2f3082 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -337,7 +337,7 @@ enum class EnumExample { /* The "object" keyword can be used to create singleton objects. -We cannot assign it to a variable, but we can refer to it by its name. +We cannot instantiate it but we can refer to its unique instance by its name. This is similar to Scala singleton objects. */ object ObjectExample { @@ -346,6 +346,11 @@ object ObjectExample { } } +fun useObject() { + ObjectExample.hello() + val someRef: Any = ObjectExample // we use objects name just as is +} + ``` ### Further Reading -- cgit v1.2.3 From 98bb8f8432e66c5721bb7cf7b808e750da9d499d Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Wed, 5 Oct 2016 14:34:08 +0300 Subject: [Kotlin/en] Add when smartcast example (#2418) --- kotlin.html.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index 4c2f3082..fe2811c5 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -317,6 +317,14 @@ fun helloWorld(val name : String) { println(smartCastExample(0)) // => false println(smartCastExample(true)) // => true + // Smartcast also works with when block + fun smartCastWhenExample(x: Any) = when (x) { + is Boolean -> x + is Int -> x > 0 + is String -> x.isNotEmpty() + else -> false + } + /* Extensions are a way to add new functionality to a class. This is similar to C# extension methods. -- cgit v1.2.3 From 7d00a22bded0b80f67e08fc807e857041f394ae5 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Wed, 5 Oct 2016 17:59:16 +0300 Subject: [Kotlin/en] Add more destructuring examples (#2419) --- kotlin.html.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index fe2811c5..d29b1471 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -175,6 +175,17 @@ fun helloWorld(val name : String) { // Objects can be destructured into multiple variables. val (a, b, c) = fooCopy println("$a $b $c") // => 1 100 4 + + // destructuring in "for" loop + for ((a, b, c) in listOf(fooData)) { + println("$a $b $c") // => 1 100 4 + } + + val mapData = mapOf("a" to 1, "b" to 2) + // Map.Entry is destructurable as well + for ((key, value) in mapData) { + println("$key -> $value") + } // The "with" function is similar to the JavaScript "with" statement. data class MutableDataClassExample (var x: Int, var y: Int, var z: Int) -- cgit v1.2.3 From 858171d7231035a286ae1b1e4aea39435dacb384 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Wed, 12 Oct 2016 17:47:41 +0800 Subject: Several changes on Kontlin. (#2335) * kotlin: remove unnecessary semicolons. Also replace code block language `java` with `kotlin`. * kotlin: change coding style (Kotlin Reference) * kotlin: anonymous function -> lambda expression Anonymous functions and lambda expressions are different in Kotlin. The code example uses `anonymous function` in the comment, while the code below is in fact lambda expressions. * Remove myself from contributors. Not for trivial changes. * kotlin: fix a typo. Thanks @geoffliu to point out this. * kotlin: change style of default parameter according to Referenec. --- kotlin.html.markdown | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index d29b1471..d1f1aae6 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -9,7 +9,7 @@ Kotlin is a statically typed programming language for the JVM, Android and the browser. It is 100% interoperable with Java. [Read more here.](https://kotlinlang.org/) -```java +```kotlin // Single-line comments start with // /* Multi-line comments look like this. @@ -42,12 +42,12 @@ fun main(args: Array) { Strings can be represented in a similar way as in Java. Escaping is done with a backslash. */ - val fooString = "My String Is Here!"; - val barString = "Printing on a new line?\nNo Problem!"; - val bazString = "Do you want to add a tab?\tNo Problem!"; - println(fooString); - println(barString); - println(bazString); + val fooString = "My String Is Here!" + val barString = "Printing on a new line?\nNo Problem!" + val bazString = "Do you want to add a tab?\tNo Problem!" + println(fooString) + println(barString) + println(bazString) /* A raw string is delimited by a triple quote ("""). @@ -87,7 +87,7 @@ fun helloWorld(val name : String) { Function arguments can optionally have a default value. The function return type, if required, is specified after the arguments. */ - fun hello(name: String = "world") : String { + fun hello(name: String = "world"): String { return "Hello, $name!" } println(hello("foo")) // => Hello, foo! @@ -119,16 +119,16 @@ fun helloWorld(val name : String) { println(even(7)) // => false // Functions can take functions as arguments and return functions. - fun not(f: (Int) -> Boolean) : (Int) -> Boolean { + fun not(f: (Int) -> Boolean): (Int) -> Boolean { return {n -> !f.invoke(n)} } // Named functions can be specified as arguments using the :: operator. val notOdd = not(::odd) val notEven = not(::even) - // Anonymous functions can be specified as arguments. + // Lambda expressions can be specified as arguments. val notZero = not {n -> n == 0} /* - If an anonymous function has only one parameter + If a lambda has only one parameter then its declaration can be omitted (along with the ->). The name of the single parameter will be "it". */ @@ -139,11 +139,11 @@ fun helloWorld(val name : String) { // The "class" keyword is used to declare classes. class ExampleClass(val x: Int) { - fun memberFunction(y: Int) : Int { + fun memberFunction(y: Int): Int { return x + y } - infix fun infixMemberFunction(y: Int) : Int { + infix fun infixMemberFunction(y: Int): Int { return x * y } } @@ -228,16 +228,16 @@ fun helloWorld(val name : String) { Sequences represent lazily-evaluated collections. We can create a sequence using the "generateSequence" function. */ - val fooSequence = generateSequence(1, {it + 1}) + val fooSequence = generateSequence(1, { it + 1 }) val x = fooSequence.take(10).toList() println(x) // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // An example of using a sequence to generate Fibonacci numbers: - fun fibonacciSequence() : Sequence { + fun fibonacciSequence(): Sequence { var a = 0L var b = 1L - fun next() : Long { + fun next(): Long { val result = a + b a = b b = result @@ -360,7 +360,7 @@ We cannot instantiate it but we can refer to its unique instance by its name. This is similar to Scala singleton objects. */ object ObjectExample { - fun hello() : String { + fun hello(): String { return "hello" } } -- cgit v1.2.3 From c1d773eab766891c8c9f5820bf18c8fafa6a8d5e Mon Sep 17 00:00:00 2001 From: Pablo Najt Date: Fri, 24 Mar 2017 14:53:41 -0300 Subject: [kotlin/all] Rename variable fooMutableDate to fooMutableData (#2688) (#2689) --- kotlin.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index d1f1aae6..a7f26126 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -189,13 +189,13 @@ fun helloWorld(val name : String) { // The "with" function is similar to the JavaScript "with" statement. data class MutableDataClassExample (var x: Int, var y: Int, var z: Int) - val fooMutableDate = MutableDataClassExample(7, 4, 9) - with (fooMutableDate) { + val fooMutableData = MutableDataClassExample(7, 4, 9) + with (fooMutableData) { x -= 2 y += 2 z-- } - println(fooMutableDate) // => MutableDataClassExample(x=5, y=6, z=8) + println(fooMutableData) // => MutableDataClassExample(x=5, y=6, z=8) /* We can create a list using the "listOf" function. -- cgit v1.2.3 From d30d6f69ca07014efdce95d771403a43423d2143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vitor=20Verona=20Biazibetti?= Date: Fri, 19 May 2017 18:34:27 -0300 Subject: [Kotlin/all] Remove whitespace in variable declaration with explicit type (#2733) * Removed whitespace in variable declaration with explicit type (Kotlin) * Removed whitespace in variable declaration with explicit type (Kotlin translations) --- kotlin.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kotlin.html.markdown') diff --git a/kotlin.html.markdown b/kotlin.html.markdown index a7f26126..ca11ee3c 100644 --- a/kotlin.html.markdown +++ b/kotlin.html.markdown @@ -36,7 +36,7 @@ fun main(args: Array) { so we don't have to explicitly specify it every time. We can explicitly declare the type of a variable like so: */ - val foo : Int = 7 + val foo: Int = 7 /* Strings can be represented in a similar way as in Java. -- cgit v1.2.3