This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val myList = listof(1,3,6,7) | |
// count pode perder os parenteses | |
val greaterThan5 = myList.count{ x -> x > 5 } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val myList = listof(1,3,6,7) | |
val greaterThan5 = myList.count({ x -> x > 5 }) | |
println(greaterThan5) // -> Imprime 2 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val sum: (Int, Int) -> Int = { x, y -> x + y } | |
println(sum(2,3)) // -> Imprime 5 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val sum: (Int, Int) -> Int = { x, y -> x + y } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val sum = { x: Int, y:Int -> x + y } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myFunction(){ | |
var myVar:String? ="Hello, World!"; | |
if(myVar != null) { | |
println(myVar.length); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myFunction(){ | |
var myVar:String? = null; | |
// Nesse caso,myVarLength será zero. | |
var myVarLength:Int = myVar?.length ?: 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myFunction(){ | |
var myVar:String? = null; | |
var myVarLength:Int? = myVar?.length; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myFunction(){ | |
var myVar:String? = null; | |
// ↓ Você não pode chamar o .length diretamente | |
var myVarLength:Int = myVar.length; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun myFunction(){ | |
var myVar:String? = null; | |
} |