kotlin-puzzlers
kotlin-puzzlers copied to clipboard
A collection of Kotlin Puzzlers
```kotlin fun main() { doSomething() doSomeThing() } fun f(block: () -> Unit) { block() } fun doSomething() { f { println("doSomething") } } fun doSomeThing() { f { println("doSomeThing") }...
Idea[source](https://www.reddit.com/r/rust/comments/5penft/parallelizing_enjarify_in_go_and_rust/dcsgk7n/): ```kotlin class SomethingᐸTᐳ fun main() { SomethingᐸTᐳ() } ``` may need to add more red herrings, but this is already interesting: it compiles and executes! but what is T?
Adds a puzzler for the `shl` bitwise operator, exploiting the fact that, like Java's bitwise operators, only the lowest 5 bits of the shift distance are considered.
Add puzzlers for the counterintuitive behavior of `ConcurrentHashMap` and `Hashtable` (respectively its subclass `Properties`) `contains(Object)` which checks if a **value** is contained. - Puzzler 1 is about the conflict with...
Adds a puzzler for a call to `joinToString` where by accident a _transform_ function was provided instead of a _separator_. Not sure if this is a good puzzler, feedback is...
There is something to consider when using extension properties in combination with delegates. I added 2 different versions of this puzzler that show the issue in slightly different ways. The...
With `range = 0.rangeTo(9)` the code would actually print `true`.
What will this print in Kotlin 1.3.X and then in Kotlin 1.4.X ? ``` enum class EnumWithConst(val theValue: Int) { One(0), Two(EnumWithConst.constValue), Three(2 * EnumWithConst.constValue); companion object { const val...
Is project dead?