1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package io.flutter.util; 6 7 /** 8 * Static convenience methods that help a method or constructor check whether 9 * it was invoked correctly (that is, whether its <i>preconditions</i> were 10 * met). 11 */ 12 public final class Preconditions { Preconditions()13 private Preconditions() {} 14 15 /** 16 * Ensures that an object reference passed as a parameter to the calling 17 * method is not null. 18 * 19 * @param reference an object reference 20 * @return the non-null reference that was validated 21 * @throws NullPointerException if {@code reference} is null 22 */ checkNotNull(T reference)23 public static <T> T checkNotNull(T reference) { 24 if (reference == null) { 25 throw new NullPointerException(); 26 } 27 return reference; 28 } 29 } 30