Is there a way to declare a method in a generic type that wraps another method for another type and declares the same thrown exceptions? The most common example I can think of for this would be AutoClosable
.
public class LazyReference<T extends AutoClosable> implements AutoClosable{
public LazyReference(Supplier<T> factory){ ... }
public T get() { ... } //get the instance for this. Create one from factory if needed
@Override
public void close() throws ????? { instance.close(); }
}
Is there a way to implement that such that the wrapper close()
would throw the same (one or more) checked exceptions that T
throws when T::close()
is called?