seba
02/07/2018, 5:27 AMmarcinmoskala
02/07/2018, 6:54 AMfun a() = 1
class A() {
fun a() = 2
fun printA() {
println((::a)())
}
}
fun main(args: Array<String>) {
A().printA() // Prints: 2
}
Is there a way I can reference top-level function instead?noncom
02/07/2018, 9:25 AMwhen
block. The type does not get inferred... here is a little reproducible gist: https://gist.github.com/noncom/ea3e57e676a799efe2943a34b06f2986fitermay
02/07/2018, 1:24 PMjkbbwr
02/07/2018, 1:38 PMrrader
02/07/2018, 3:45 PMjkbbwr
02/07/2018, 4:25 PMbeatbrot
02/07/2018, 5:33 PMShawn
02/07/2018, 5:44 PMevkaky
02/07/2018, 5:55 PMT variable = default(T)
in the C#
My first try in kotlin:
data class Node<K>(val key: K)
class Container<K> {
var head = Node<K>() // err here, I have to specify *key* prop in the node ctor, but how?
}
What can I use?adams2
02/08/2018, 12:44 AMnoncom
02/08/2018, 9:17 AMdiesieben07
02/08/2018, 11:00 AMKClass
and you'd know that it implements the factory interface.
But yes, all this is very messy and contrived, you'd be better off just passing around a lambda instead of the KClass
.tristanlim
02/08/2018, 11:18 AMalllex
02/08/2018, 6:25 PMfun bar(x: Int): Int = when (x) {
0 -> {
listOf(1).forEach { return 0 }
error("never")
}
else -> 10
}
Shawn
02/08/2018, 6:32 PMKaj
02/08/2018, 7:37 PMResponseEntity
specifically?aphex
02/08/2018, 10:45 PMcedric
02/08/2018, 11:30 PMif
but it definitely beats Smalltalk’s ifTrue
and ifFalse
edwardwongtl
02/09/2018, 4:43 AM_
inside a lambda does not change the fact that the compiler will automatically assign a value to it
YMobile
02/09/2018, 8:53 AMkoufa
02/09/2018, 1:22 PMclass A(val name: String, val country: String)
class B(val name: String, val age: Int)
class C(val name: String, val age: Int, val country: String)
What is the idiomatic way in Kotlin to combine two lists say List<A>
and List<B>
to a new List<C>
if C
is produced from A and B
if a.name == b.name
?Dominik.sittel
02/09/2018, 2:26 PMDominik.sittel
02/09/2018, 2:41 PMkarelpeeters
02/09/2018, 2:57 PMapply
?Gerard de Leeuw
02/09/2018, 3:09 PMShawn
02/09/2018, 4:15 PMbj0
02/09/2018, 6:06 PMmap {}
can't be short-circuited like a forloop can right?jimn
02/09/2018, 9:57 PMbhupenk
02/10/2018, 4:27 PMbhupenk
02/10/2018, 4:27 PMCzar
02/10/2018, 5:27 PM