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 lambdaName:(InputType, InputType , ..) -> OutputType = {arguementN:InputType, argumentN:InputType -> body} | |
// greeter ("Michael", "duplessis") | |
// "Hello Michael du Plessis" | |
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 name="michael du Plessis" | |
println(name.initials()) | |
} | |
fun String.initials():String{ | |
val values:List<String> =this.split(' ') | |
val firstLetter:String = values[0].substring(0,1) |
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
import java.lang.Exception | |
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val p:Person = Person("Michael", 18) | |
println("Try Check if age throws an exception") | |
try { |
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
import java.lang.Exception | |
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val p:Person = Person("Michael", 10) | |
println("Try Check if age throws an exception") | |
try { |
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
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val p:Person = Person("Michael", 10) | |
if (p.age<12){ | |
throw InvalidAgeException(p.age, "WTF dude") | |
} |
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
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val obj: Any = getStuff("1") | |
val casted: Int? = obj as? Int | |
println(casted) | |
} |
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
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val obj: Any = getStuff("5") | |
val casted: Persons = obj as Persons | |
println(casted.name) | |
} |
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
import java.time.temporal.TemporalAmount | |
import kotlin.reflect.typeOf | |
fun main(args: Array<String>) { | |
val obj: Any = Persons("Bob") | |
if (obj is String) { | |
println("It is") | |
} else { |
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
import java.util.concurrent.TimeUnit | |
import kotlin.random.Random | |
import kotlin.system.measureNanoTime | |
fun main(args: Array<String>) { | |
var name: String? = "Donn" | |
// Tenary operator | |
// kotlin doe not have a teneary operator | |
// so you can not do this |
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
import java.util.concurrent.TimeUnit | |
import kotlin.random.Random | |
import kotlin.system.measureNanoTime | |
fun main(args: Array<String>) { | |
var name: String? = "Donn" | |
// Tenary operator | |
// kotlin doe not have a teneary operator | |
// so you can not do this |
NewerOlder