fork(2) download
  1. import java.io.Closeable;
  2. import java.io.IOException;
  3.  
  4. class MyCloseable implements Closeable {
  5. private static MyCloseable instance = new MyCloseable();
  6.  
  7. private MyCloseable() {}
  8.  
  9. public static MyCloseable getInstance() {
  10. return instance;
  11. }
  12.  
  13. @Override
  14. public void close() throws IOException {
  15. System.out.println("Close");
  16. }
  17. }
  18.  
  19. public class Main {
  20.  
  21. public static void main(String[] args) {
  22. try (MyCloseable closeable = MyCloseable.getInstance()) {
  23.  
  24. } catch (IOException e) {
  25.  
  26. }
  27. }
  28. }
  29.  
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Close