masted
03/08/2016, 12:56 PMvoddan
03/08/2016, 1:03 PMbreak the contract ofnot sure the contract is applicable to Kotlinby throwingcompareTo
voddan
03/08/2016, 1:04 PMvoddan
03/08/2016, 1:05 PMdalexander
03/08/2016, 1:09 PMnatpryce
03/08/2016, 1:56 PMnatpryce
03/08/2016, 1:57 PMoperator fun <T, U:T> Klass<T>.compareTo(u: Klass<U>) = 1
operator fun <U, T:U> Klass<T>.compareTo(u:Klass<U>) = -1
kirillrakhman
03/08/2016, 1:57 PMKClass
but generally , you don't know themkirillrakhman
03/08/2016, 1:58 PMeshioji
03/08/2016, 3:07 PMenumMapOf
? Seems like a reasonable thing to add, but AFAIK it’s not there yetcbruegg
03/08/2016, 3:14 PMeshioji
03/08/2016, 3:24 PMeshioji
03/08/2016, 3:24 PMdamian
03/08/2016, 3:28 PMenum class Direction(val temperature: String? = null) {
NORTH("cold"), SOUTH("warm"), WEST(), EAST();
}
damian
03/08/2016, 3:29 PMeshioji
03/08/2016, 3:30 PMEnumMap
dalexander
03/08/2016, 3:30 PMmapOf(<enumval1> to <val1>, <enumval2> to <val2>)
?jw
03/08/2016, 3:30 PMEnumMap
is more efficient (just like EnumSet
)eshioji
03/08/2016, 3:31 PMeshioji
03/08/2016, 3:31 PMjw
03/08/2016, 3:31 PMdalexander
03/08/2016, 3:31 PMeshioji
03/08/2016, 3:32 PMlinkedMapOf
and hashMapOf
etceshioji
03/08/2016, 4:17 PM*MapOf
methods, enumMapOf
would have to have access to the enum’s class object. So either we can use the signature enumMapOf(pairs)
and disallow creating a empty enum map (because we won’t be able to get hold of the class object), or we could require the user to pass the class object as a parameter.jw
03/08/2016, 4:22 PMeshioji
03/08/2016, 4:23 PMjw
03/08/2016, 4:23 PMeshioji
03/08/2016, 4:23 PMjw
03/08/2016, 4:25 PMinline fun <reified K : Enum<K>, V> enumMapOf(vararg pairs: Pair<K, V>): EnumMap<K, V> {
val map = EnumMap<K, V>(K::class.java)
pairs.forEach { map.put(it.first, it.second) }
return map
}
eshioji
03/08/2016, 4:26 PM