Overloading operations via extension functions.

Also inline useless TranslationUtils#zeroLiteral. Eliminate dead code.
This commit is contained in:
Pavel V. Talanov
2012-07-19 20:40:03 +04:00
parent 36184ded3b
commit 803be4b0d5
9 changed files with 110 additions and 53 deletions
@@ -0,0 +1,16 @@
package foo
import java.util.*
fun <T> ArrayList<T>.plusAssign(other: Collection<T>) {
addAll(other)
}
fun box(): Boolean {
var v1 = ArrayList<String>()
val v2 = ArrayList<String>()
v1.add("foo")
v2.add("bar")
v1 += v2
return (v1.size() == 2 && v1[0] == "foo" && v1[1] == "bar")
}
@@ -0,0 +1,19 @@
package foo
import java.util.*
fun <T> ArrayList<T>.plus(other: Collection<T>): List<T> {
val c = ArrayList<T>()
c.addAll(this)
c.addAll(other)
return c
}
fun box(): Boolean {
var v1 = ArrayList<String>()
val v2 = ArrayList<String>()
v1.add("foo")
v2.add("bar")
v1 += v2
return (v1.size() == 2 && v1[0] == "foo" && v1[1] == "bar")
}
@@ -0,0 +1,20 @@
package foo
import java.util.*
fun <T> ArrayList<T>.plus(other: Collection<T>): List<T> {
val c = ArrayList<T>()
c.addAll(this)
c.addAll(other)
return c
}
fun box(): Boolean {
var v1 = ArrayList<String>()
v1.add("foo")
val v2 = ArrayList<String>()
v2.add("bar")
val v = v1 + v2
return (v.size() == 2 && v[0] == "foo" && v[1] == "bar")
}
@@ -0,0 +1,12 @@
package foo
class A(val c: Int) {}
fun A.inc() = A(5)
fun A.dec() = A(10)
fun box(): Boolean {
var a = A(1)
return ((++a).c == 5 && (a++).c == 5 && (--a).c == 10 && (a--).c == 10)
}