more progress on traits

This commit is contained in:
Alex Tkachman
2011-09-12 21:23:42 +03:00
parent 4c5d74ea93
commit cf639cf084
9 changed files with 186 additions and 25 deletions
+15
View File
@@ -0,0 +1,15 @@
trait AL {
fun get(index: Int) : Any? = null
}
trait ALE<T> : AL {
fun getOrNull(index: Int, value : T) = get(index) as? T ?: value
}
class SmartArrayList() : ALE<String> {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrNull(0, "239")) "OK" else "fail"
}
@@ -0,0 +1,15 @@
open class AL<T> {
fun get(index: Int) : T? = null
}
trait ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value
}
class SmartArrayList() : ALE<String>, AL<String> {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrValue(0, "239")) "OK" else "fail"
}