Skip to content

Instantly share code, notes, and snippets.

View kajetan-suchanski's full-sized avatar
🌍
Sharing

kaj kajetan-suchanski

🌍
Sharing
View GitHub Profile
class Ads {
fun display() {
Log.i("Ads", "The view was beautifully decorated with several ads")
}
}
class Analytics {
fun analyze() {
Log.i("Analytics", "Your private data was obtained anonymously")
}
}
class Drive {
fun sync() {
Log.i("Drive", "The drive has been synchronized")
}
}
class ListItem<ItemType>(val item: ItemType, val printer: AbstractItemPrinter<ItemType>)
abstract class AbstractItemPrinter<ItemType> {
abstract fun print(item: ItemType)
@Suppress("UNCHECKED_CAST") // It is a safe cast... when used properly ;)
fun delegatePrint(item: Any?) {
print(item as ItemType)
}
}
class Cat {
fun meow() {
println("Meow?")
}
}
class ThisClass
fun classCheckExample() {
val listOfAny = listOf<Any>(ApplePie(), Cheesecake(), Coffee(), Cat(), ThisClass())
interface Consumable {
fun consume()
}
class ApplePie : Consumable {
override fun consume() {
println("Yummy apple pie!")
}
}
class ApplePie
class Cheesecake
class Coffee
fun listOfAnyExample() {
val listOfAny = listOf<Any>(ApplePie(), Cheesecake(), Coffee())
listOfAny.forEach { println("I am ${it.javaClass.simpleName}.") }
}
const c = false && "true" // === false && "false"
const h = "true" && false // === "false" && false
const a = true && "true"
const o = "true" && true
const t = true && "false"
const i = "false" && true
const k = [c, h, a, o, t, i]
for(let result of k)
console.log(`${typeof result} ${result}`)