implicit final
class
TryThenClose[T <: AnyRef { def close(): Unit }] extends AnyVal
Instance Constructors
-
new
TryThenClose(self: T)
Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
getClass(): Class[_ <: AnyVal]
-
final
def
isInstanceOf[T0]: Boolean
-
val
self: T
-
def
toString(): String
-
def
tryThenClose[R](f: (T) ⇒ R): R
Inherited from AnyVal
Inherited from NotNull
Inherited from Any
Implementation for a
tryThenClose
extension method meant for closeable resources, like input streams, for safe disposal of resources.This example:
Is equivalent to this:
Actually for this to work it doesn't have to be a Java Closable as the type-checking is based on structural typing (yet because it's implemented as a macro, the actual call is not reflective).