kirillrakhman
06/26/2017, 6:03 PMTResult value;
return map.TryGet(key, out value) ? value : null
kirillrakhman
06/26/2017, 6:04 PMgroostav
06/26/2017, 6:07 PMgroostav
06/26/2017, 6:09 PMdata class Coordinate(val key: String, val value: Double)
fun myDomainFunctions(input: List<Coordinate>){
val result = input["x3"]
}
operator fun List<Coordinate>.get(key: String): Double = //...
but then I'd have to carefully consider how the generic v-table List.get(index: Int)
miight collide with such an extension functiongroostav
06/26/2017, 6:11 PMfun List<Coordinate>.asMap()
groostav
06/26/2017, 6:13 PMoperator fun Map<K, V>.invoke
...kirillrakhman
06/26/2017, 6:45 PMkirillrakhman
06/26/2017, 6:45 PMdamian
07/07/2017, 3:36 PMdanneu
07/09/2017, 12:46 AMkarelpeeters
07/09/2017, 10:28 PMbmo
07/11/2017, 7:20 AMempty
(or something else) that could be added to an abstract class or an interface. The idea would be that adding the keyword would implement every method with an empty implementation. That would be particularly helpful when you want to implement only one method of an interface that has a lot of methods. E.g. :
class MyClass : MyInterface by empty MyInterface() {
override fun onlyOneMethod() {
//...
}
}
Of course, it would return null
for nullable object, 0 for numeric value, false for boolean and "" for String.
For non-nullable objects return, an implementation would still be required.
This keyword could also be used to create a new class :
empty class MyInterface()
I understand this can be easily achieved by generating an empty implementation of an interface through the IDE but this keyword would make the code less verbosekirillrakhman
07/11/2017, 8:28 AMkirillrakhman
07/11/2017, 8:31 AMAnimatorListenerAdapter
kirillrakhman
07/11/2017, 8:32 AMjava.lang.reflect.Proxy
, not sure how good the performance will bebmo
07/11/2017, 8:33 AMkirillrakhman
07/11/2017, 8:44 AMj.l.r.Proxy
interface I {
fun int(): Int
fun double(): Double
}
object Foo : I by proxy() {
override fun double() = 1.0
}
fun main(args: Array<String>) {
println(<http://Foo.int|Foo.int>())
println(Foo.double())
}
inline fun <reified T> proxy() = proxy(T::class.java)
@Suppress("UNCHECKED_CAST")
fun <T> proxy(c: Class<T>): T {
return Proxy.newProxyInstance(c.classLoader, arrayOf(c), { _, method, _ ->
when (method.returnType) {
Int::class.javaPrimitiveType, Int::class.javaObjectType -> 0
Short::class.javaPrimitiveType, Short::class.javaObjectType -> 0.toShort()
Char::class.javaPrimitiveType, Char::class.javaObjectType -> 0.toChar()
Long::class.javaPrimitiveType, Long::class.javaObjectType -> 0.toLong()
Float::class.javaPrimitiveType, Float::class.javaObjectType -> 0f
Double::class.javaPrimitiveType, Double::class.javaObjectType -> 0.0
else -> null
}
}) as T
}
bmo
07/11/2017, 8:54 AMgildor
07/11/2017, 8:58 AMelect
07/13/2017, 2:41 PMreset()
for? https://youtrack.jetbrains.com/issue/KT-9327#comment=27-2325315udalov
elect
07/13/2017, 2:50 PMreset()
would then isInitialized
return false
?udalov
breandan
07/13/2017, 6:01 PMbreandan
07/13/2017, 6:04 PMmyClass.property1.nested.property2 = value
, I would like to expose property2
as a delegated property of myClass
, ie. myClass.property2 = value
karelpeeters
07/13/2017, 6:05 PMagomez
07/13/2017, 6:07 PMbreandan
07/13/2017, 6:08 PMoperator fun <T> KProperty0<T>.getValue(thisRef: Any?, property: KProperty<*>) = get()
operator fun <T> KMutableProperty0<T>.setValue(thisRef: Any?, property: KProperty<*>, value: T) = set(value)
breandan
07/13/2017, 6:09 PMvar propertyAlias by property1.nested::property2
breandan
07/13/2017, 6:13 PMvar propertyAlias
get() = property1.nested.property2
set(value) {
property1.nested.property2 = value
}
which is much more verbose