Skip to content

Instantly share code, notes, and snippets.

View ajoz's full-sized avatar

Andrzej Jóźwiak ajoz

View GitHub Profile
@ajoz
ajoz / RefinedTypes.kt
Last active May 31, 2020 22:24
Refined types in Kotlin
class Refined<A : Any>(
default: A,
private val errorMsgGen: (A) -> String = {
"Value: $it does not meet its constraints!"
},
private val validator: (A) -> Boolean = { true }
) : ReadWriteProperty<Refined<A>?, A> {
private var backingField: A = default
override operator fun getValue(thisRef: Refined<A>?, property: KProperty<*>): A {
@ajoz
ajoz / PsvmInKotlin.kt
Created June 5, 2017 09:19
public static void main function in Kotlin
class Foo {
// This will not work because its not a static method!
// You cannot annotate it with @JvmStatic (usable only
// in objects and companion objects)
// You have 4 options:
fun main(args: Array<String>) {
prinltn("This won't work as expected")
}
// this will clash with main above during compilation!