Add Intrinsics.areEqual()

It's more safe, short and less error-prone (especially w.r.t. nullability of
generic types)
This commit is contained in:
Alexander Udalov
2013-02-05 22:06:39 +04:00
parent 41b379497d
commit 1021ec5ff4
5 changed files with 30 additions and 122 deletions
+6 -1
View File
@@ -20,6 +20,7 @@ import jet.Function0;
import java.util.*;
@SuppressWarnings("unused")
public class Intrinsics {
private Intrinsics() {
}
@@ -76,7 +77,11 @@ public class Intrinsics {
public static int compare(int thisVal, int anotherVal) {
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
public static boolean areEqual(Object first, Object second) {
return first == null ? second == null : first.equals(second);
}
public static <R> R stupidSync(Object lock, Function0<R> block) {
synchronized (lock) {
return block.invoke();