1

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.