
framework.Defer Maven / Gradle / Ivy
package framework;
import java.util.function.Consumer;
/**
* use any object at try with resources
* @param object type
*/
public class Defer implements AutoCloseable {
/**
* instance
*/
T instance;
/**
* close action
*/
Consumer close;
/**
* @param instance instance
* @param close close
*/
public Defer(T instance, Consumer close) {
this.instance = instance;
this.close = close;
}
/* (non-Javadoc)
* @see java.lang.AutoCloseable#close()
*/
@Override
public void close() {
close.accept(instance);
}
/**
* @return instance
*/
public T get() {
return instance;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy