ribesg
02/28/2017, 9:24 AMfun testKek() {
class A {
val x = HashMap<String, Int>()
operator fun get(s: String) = x[s]!!
init {
x["topkek"] = 42
}
}
println("${A()["topkek"]}")
}
elect
02/28/2017, 9:25 AMelect
02/28/2017, 9:26 AMelect
02/28/2017, 9:26 AMaimozg
02/28/2017, 9:26 AMMap.get
in Java is Object->Object, and K->V in Kotlinaimozg
02/28/2017, 9:27 AMelect
02/28/2017, 9:27 AMaimozg
02/28/2017, 9:27 AMelect
02/28/2017, 9:27 AMmg6maciej
02/28/2017, 9:29 AMuniforms.getValue(s)
on K 1.1.elect
02/28/2017, 9:33 AMelect
02/28/2017, 9:34 AMinstance["x"]
seems nicemg6maciej
02/28/2017, 9:34 AM!!
and having to declare return type, it is indeed nice.alilotfi
02/28/2017, 9:35 AMfun disconnect(code: Int = NORMAL_CLOSURE) {}
instead of simply
fun disconnect(code = NORMAL_CLOSURE) {}
miha-x64
02/28/2017, 9:38 AMbernhard
02/28/2017, 9:45 AMalilotfi
02/28/2017, 9:46 AMalilotfi
02/28/2017, 9:47 AMval NORMAL_CLOSURE = 1000
alilotfi
02/28/2017, 9:48 AMNORMAL_CLOSURE
can also be Any
(but it is inferred as Int
)miha-x64
02/28/2017, 9:50 AMBigInteger
, and then to BigDecimal
, in different versions of library, you will get different (and binary incompatible) signatures and expose some implementation details.
In case I described, fun disconnect(code: Number = NORMAL_CLOSURE)
is preferred.alilotfi
02/28/2017, 9:53 AMNORMAL_CLOSURE
is part of API itself, so changing it is same as changing default argument type to something elsekingsley
02/28/2017, 10:23 AMalilotfi
02/28/2017, 10:33 AMdstarcev
02/28/2017, 3:40 PMfun <T> Sequence<T>.minus(vararg elements: T): Sequence<T> = this.minus<T>(elements)
aaverin
02/28/2017, 3:48 PMclass MultiMap<K, V> : HashMap<K, MutableList<V>>() {
fun put(key: K, value: V) {
var entries = get(key)
if (entries == null) {
entries = mutableListOf<V>()
put(key, entries)
}
entries.add(value)
}
}
That in Java Spring project fails to compile with:
MultiMap.kt: (5, 7): Inherited platform declarations clash: The following declarations have the same JVM signature (getOrDefault(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;):
fun getOrDefault(key: K, defaultValue: MutableList<V>): MutableList<V>
fun getOrDefault(key: Any!, defaultValue: MutableList<V>!): MutableList<V>!
What would a proper fix?aaverin
02/28/2017, 3:53 PMpakoito
02/28/2017, 11:53 PMpakoito
02/28/2017, 11:54 PMgroostav
02/28/2017, 11:55 PMpakoito
02/28/2017, 11:55 PM