void testArr3(@Nullable Object @NonNull [] a) { // use as statement: NullnessUtil.castNonNullDeep(a); a.toString(); // TODO: @EnsuresNonNull cannot express that // all the array components are non-null. // a[0].toString(); }
void testArr1b(@Nullable Object @Nullable [] a) { // one way to use as a cast: @NonNull Object[] l2 = NullnessUtil.castNonNullDeep(a); // Careful, the non-deep version only casts the main modifier. // :: error: (assignment.type.incompatible) @NonNull Object[] l2b = NullnessUtil.castNonNull(a); // OK @Nullable Object[] l2c = NullnessUtil.castNonNull(a); }
void testMultiArr2(@Nullable Object @NonNull [] @Nullable [] a) { // another way to use as a cast: NullnessUtil.castNonNullDeep(a)[0][0].toString(); }
void testMultiArr1(@Nullable Object @NonNull [] @Nullable [] a) { // :: error: (assignment.type.incompatible) :: error: (accessing.nullable) @NonNull Object l3 = a[0][0]; // one way to use as a cast: @NonNull Object[][] l4 = NullnessUtil.castNonNullDeep(a); }
public static void main(String[] args) { Object[] @Nullable [] err = new Object[10][10]; Object[][] e1 = NullnessUtil.castNonNullDeep(err); e1[0][0].toString(); }
void testMultiArr3(@Nullable Object @Nullable [] @Nullable [] @Nullable [] a) { // :: error: (dereference.of.nullable) :: error: (accessing.nullable) a[0][0][0].toString(); // another way to use as a cast: NullnessUtil.castNonNullDeep(a)[0][0][0].toString(); }