Supported SAM adapters with type parameters.

This commit is contained in:
Evgeny Gerashchenko
2013-04-18 17:15:40 +04:00
parent db8d285b25
commit 8c4e45de9a
7 changed files with 73 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
import java.util.*;
class WeirdComparator {
public static <T> T max(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
public static <T extends CharSequence> T max2(Comparator<T> comparator, T value1, T value2) {
return comparator.compare(value1, value2) > 0 ? value1 : value2;
}
}

View File

@@ -0,0 +1,9 @@
fun box(): String {
val result = WeirdComparator.max<String>({ a, b -> a.length - b.length }, "java", "kotlin")
if (result != "kotlin") return "Wrong: $result"
val result2 = WeirdComparator.max2<String>({ a, b -> a.length - b.length }, "java", "kotlin")
if (result2 != "kotlin") return "Wrong: $result"
return "OK"
}