interface BinaryNumber object Zero : BinaryNumber object One : BinaryNumber fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 else -> throw IllegalStateException() }c }d
interface BinaryNumber object Zero : BinaryNumber object One : BinaryNumber fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 }c }d
interface BinaryNumber object Zero : BinaryNumber object One : BinaryNumber fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 else -> throw IllegalStateException() }c }d
interface BinaryNumber object Zero : BinaryNumber object One : BinaryNumber class Magic() : BinaryNumber() { fun abracadabra() { // ... } } fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 else -> throw IllegalStateException() }c }d
interface BinaryNumber object Zero : BinaryNumber object One : BinaryNumber fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 else -> throw IllegalStateException() }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 else -> throw IllegalStateException() }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() class Magic() : BinaryNumber() {z fun abracadabra() {w // ... }t }r fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() class Magic() : BinaryNumber() {z fun abracadabra() {w // ... }t }r fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() class Magic() : BinaryNumber() {z fun abracadabra() {w // ... }t }r fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 is Magic -> this.abracadabra() }c }d
sealed class BinaryNumber object Zero : BinaryNumber() object One : BinaryNumber() class Magic() : BinaryNumber() { fun abracadabra() { // ... } } fun BinaryNumber.toInt():Int {a return when (this) {b is One -> 1 is Zero -> 0 is Magic -> this.abracadabra() }c }d
fun sumUp(items: Collection<*>) {a val ints = items as? List ?: return println("We got a list of ints") println(ints.sum()) }c val strings: List = listOf("a", "b") sumUp(strings)
fun sumUp(items: Collection<*>) {a val ints = items as? List ?: return println("We got a list of ints") println(ints.sum()) }c val strings: List = listOf("a", "b") sumUp(strings) ----- We got a list of ints Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
fun sumUp(items: Collection<*>) {a val ints = items as? List ?: return println("We got a list of ints") println(ints.sum()) }c val strings: List = listOf("a", "b") sumUp(strings)
fun sumUp(items: Collection) {a val ints = items as? List ?: return println("We got a list of ints") println(ints.sum()) }c val strings: List = listOf("a", "b") sumUp(strings)
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f listOf("a", 1, 0x0, 2L, 'u') .filterIsInstance()
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f listOf("a", 1, 0x0, 2L, 'u') .filterIsInstance()
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f listOf("a", 1, 0x0, 2L, 'u') .filterIsInstance()
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
inline fun Iterable<*>.filterIsInstance(): List {a val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
inline fun Iterable<*>.filterIsInstance(): List val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
inline fun Iterable<*>.filterIsInstance(): List val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f
inline fun Iterable<*>.filterIsInstance(): List val destination = mutableListOf() for (element in this) {c if (element is T) {d destination.add(element) }p }e return destination }f listOf("a", 1, 0x0, 2L, 'u') .filterIsInstance()