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
var nullableGreeting: String? = "Hello, World" | |
nullableGreeting = null // Works |
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
var greeting: String = "Hello, World" | |
greeting = null // Compilation Error |
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
suspend fun getStatus(): List<String> { | |
val currentUserDeferred = someApi.fetchUser() | |
val currentCompanyDeferred = someApi.fetchCompany() | |
return listOf(currentUserDeferred.await(), currentCompanyDeferred.await()) | |
} |
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
async function getStatus() { | |
const currentUserPromise = someApi.fetchUser(); | |
const currentCompanyPromise = someApi.fetchCompany(); | |
return await Promise.all([currentUserPromise, currentCompanyPromise]); | |
} |
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
data class Movie( | |
val name: String, | |
val rating: Int, | |
val director: String | |
) | |
val movie1 = Movie("Back to the Future", 5, "Bob Zemeckis") | |
val movie1 = Movie("Star Wars: Episode IV - A New Hope", 5, "George Lucas") |
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
const movie1 = { | |
name: "Back to the Future", | |
rating: 5, | |
director: "Bob Zemeckis" | |
} | |
const movie2 = { | |
name: "Star Wars: Episode IV - A New Hope", | |
rating: 5, | |
director: "George Lucas" | |
} |
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
class Monster(val name: String, val color: String, val numEyes: Int) { | |
fun speak(likes: String):String { | |
return "My name is $name and I like $likes" | |
} | |
} | |
var nhama = Monster("Nhama", "red", 1) | |
// Kotlin doesn't have a `new` keyword - you instantiate a class by calling it directly | |
nhama.speak("guacamole") | |
// "My name is Nhama and I like guacamole" |
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
class Monster { | |
constructor(name, color, numEyes) { | |
this.name = name; | |
this.color = color; | |
this.numEyes = numEyes; | |
} | |
speak(likes) { | |
return `My name is ${this.name} and I like ${likes}`; | |
} | |
} |
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 weatherReport(location) { | |
// Make an Ajax request to fetch the weather... | |
return Pair(72, "Mostly Sunny") // Pair is a standard class in Kotlin that represents a generic pair of two values | |
} | |
val (temp, forecast) = weatherReport("Berkeley, CA") |
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
function weatherReport(location) { | |
// Make an Ajax request to fetch the weather... | |
return [72, "Mostly Sunny"]; | |
} | |
const [temp, forecast] = weatherReport("Berkeley, CA"); |