AutoCloseable.hx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package java.lang;
  2. /*
  3. * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /**
  27. * A resource that must be closed when it is no longer needed.
  28. *
  29. * @author Josh Bloch
  30. * @since 1.7
  31. */
  32. @:require(java7) extern interface AutoCloseable
  33. {
  34. /**
  35. * Closes this resource, relinquishing any underlying resources.
  36. * This method is invoked automatically on objects managed by the
  37. * {@code try}-with-resources statement.
  38. *
  39. * <p>While this interface method is declared to throw {@code
  40. * Exception}, implementers are <em>strongly</em> encouraged to
  41. * declare concrete implementations of the {@code close} method to
  42. * throw more specific exceptions, or to throw no exception at all
  43. * if the close operation cannot fail.
  44. *
  45. * <p><em>Implementers of this interface are also strongly advised
  46. * to not have the {@code close} method throw {@link
  47. * InterruptedException}.</em>
  48. *
  49. * This exception interacts with a thread's interrupted status,
  50. * and runtime misbehavior is likely to occur if an {@code
  51. * InterruptedException} is {@linkplain Throwable#addSuppressed
  52. * suppressed}.
  53. *
  54. * More generally, if it would cause problems for an
  55. * exception to be suppressed, the {@code AutoCloseable.close}
  56. * method should not throw it.
  57. *
  58. * <p>Note that unlike the {@link java.io.Closeable#close close}
  59. * method of {@link java.io.Closeable}, this {@code close} method
  60. * is <em>not</em> required to be idempotent. In other words,
  61. * calling this {@code close} method more than once may have some
  62. * visible side effect, unlike {@code Closeable.close} which is
  63. * required to have no effect if called more than once.
  64. *
  65. * However, implementers of this interface are strongly encouraged
  66. * to make their {@code close} methods idempotent.
  67. *
  68. * @throws Exception if this resource cannot be closed
  69. */
  70. @:overload public function close() : Void;
  71. }