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
| func f<T: ExpressibleByIntegerLiteral>() -> T { | |
| return 1 // as T | |
| } | |
| let int: Int = f() | |
| let double: Double = f() |
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 B<out Any> {} | |
| val b: B<String> = B() | |
| val b_: B<out Any> = b // out あり | |
| b_ | |
| // B@5327a06e | |
| val b: B<String> = B() | |
| val b_: B<Any> = b // out なし | |
| b_ |
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 A {} | |
| fun A(v: Int): A = A() | |
| /* | |
| A() | |
| A(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
| class A {} | |
| fun A(v: Int): A = A() | |
| /* | |
| A() | |
| A(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
| var i = 0 | |
| repeat { [_ = print("capture list")] | |
| i += 1 | |
| } while i < 3 | |
| /* | |
| capture list | |
| capture list | |
| capture list | |
| */ |
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 v = true | |
| repeat { [v] | |
| print(v) | |
| v = false | |
| print(v) | |
| } while v | |
| var i = 0 | |
| repeat { [_ = print("capture list")] | |
| i += 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
| class A : Iterable<String> { | |
| override operator fun iterator(): Iterator<String> = MyIterator() | |
| } | |
| class MyIterator: Iterator<String> { | |
| override operator fun hasNext(): Boolean = Math.random() < 0.5 | |
| override operator fun next(): String = "a" | |
| } | |
| // A().forEach({ print(it)}) |
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 A(val v1: Int) { | |
| init { | |
| require(v1 < 0, {"aaaaaa"}) | |
| } | |
| override fun hashCode(): Int { | |
| return v1 | |
| } | |
| override fun equals(other: Any?): Boolean { |
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
| // elements.size == 0 | |
| object EmptySet : Set<Nothing> | |
| // elements.size == 1 | |
| java.util.Collections.singleton(element) | |
| // elements.size > 1 | |
| public typealias LinkedHashSet<E> = java.util.LinkedHashSet<E> |
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
| // Swift | |
| func TODO() -> Never { fatalError() } | |
| func start() -> String { return TODO() } // 返り値の型が Never でもコンパイル通る | |
| // Kotlin | |
| fun TODO(): Nothing = throw NotImplementedError() | |
| fun start(): String = TODO() |