| 1 |
import java.lang.ref.WeakReference; |
| 2 |
|
| 3 |
class Ternary<F> { |
| 4 |
void m1(boolean b) { |
| 5 |
String s = b ? new String("foo") : null; |
| 6 |
} |
| 7 |
|
| 8 |
void m2(boolean b) { |
| 9 |
String s = b ? null : new String("foo"); |
| 10 |
} |
| 11 |
|
| 12 |
@SuppressWarnings("nullness") // Don't want to depend on @Nullable |
| 13 |
String m3(boolean b) { |
| 14 |
return b ? new String("foo") : null; |
| 15 |
} |
| 16 |
|
| 17 |
void m4(boolean b) { |
| 18 |
String[] s = b ? new String[] {""} : null; |
| 19 |
} |
| 20 |
|
| 21 |
void m5(boolean b) { |
| 22 |
Object o = new Object(); |
| 23 |
String s = b ? (String) o : null; |
| 24 |
} |
| 25 |
|
| 26 |
void m6(boolean b) { |
| 27 |
String p = "x*((("; |
| 28 |
String s = b ? p : null; |
| 29 |
} |
| 30 |
|
| 31 |
class Generic<T extends Object> { |
| 32 |
void cond(boolean b, T p1, T p2) { |
| 33 |
p1 = b ? p1 : p2; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
void array(boolean b) { |
| 38 |
String[] s = b ? new String[] {""} : null; |
| 39 |
} |
| 40 |
|
| 41 |
void generic(boolean b, Generic<String> p) { |
| 42 |
Generic<String> s = b ? p : null; |
| 43 |
} |
| 44 |
|
| 45 |
void primarray(boolean b) { |
| 46 |
long[] result = b ? null : new long[10]; |
| 47 |
} |
| 48 |
|
| 49 |
void vars() { |
| 50 |
// String and Integer generate an intersection type. |
| 51 |
String c = null; |
| 52 |
Integer m = null; |
| 53 |
Object s = (m != null) ? m : c; |
| 54 |
} |
| 55 |
|
| 56 |
void vars2() { |
| 57 |
// String and Integer generate an intersection type. |
| 58 |
String c = null; |
| 59 |
Integer m = null; |
| 60 |
Object s = (m != null) ? m : c; |
| 61 |
} |
| 62 |
|
| 63 |
public void test(MyWeakRef<? extends F> existingRef) { |
| 64 |
@SuppressWarnings("known.nonnull") |
| 65 |
F existing = existingRef == null ? null : existingRef.get(); |
| 66 |
} |
| 67 |
|
| 68 |
private static final class MyWeakRef<L> extends WeakReference<L> { |
| 69 |
|
| 70 |
public MyWeakRef(L referent) { |
| 71 |
super(referent); |
| 72 |
} |
| 73 |
} |
| 74 |
} |