1 /* 2 * Copyright 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.camera2.cts.helpers; 18 19 /** 20 * Defines an interface for classes that can (or need to) be closed once they 21 * are not used any longer; calling the {@code close} method releases resources 22 * that the object holds.</p> 23 * 24 * <p>This signifies that the implementor will never throw checked exceptions when closing, 25 * allowing for more fine grained exception handling at call sites handling this interface 26 * generically.</p> 27 * 28 * <p>A common pattern for using an {@code UncheckedCloseable} resource: 29 * <pre> {@code 30 * // where <Foo extends UncheckedCloseable> 31 * UncheckedCloseable foo = new Foo(); 32 * try { 33 * ...; 34 * } finally { 35 * foo.close(); 36 * } 37 * }</pre> 38 */ 39 public interface UncheckedCloseable extends AutoCloseable { 40 41 /** 42 * Closes the object and release any system resources it holds. 43 * 44 * <p>Does not throw any checked exceptions.</p> 45 */ 46 @Override close()47 void close(); 48 } 49