I'm very new to Scala, so please excuse my basic question.
I'm trying to get Scala-Arm to manage the release of a class member, but having trouble with scoping.
Although the following code compiles, it fails with
java.lang.NoSuchMethodError: resource.ManagedResource.reflect()Ljava/lang/Object;
on the reflect call. So it seems the the managed_file
is being released immediately.
For local variables I have used the for (managed_file <- managed(...))
syntax but I can't see what to do here.
Suggestions anyone?
class Writer(outputPath: String){
val managed_file = managed(new FileOutputStream(new File(outputPath)))
def write(something : SomeClass) {
var bos = new ByteArrayOutputStream
var dos = new DataOutputStream(bos)
try {
dos.write(Marshal.dump(something))
bos.writeTo(managed_file.reflect)
}
finally {
dos.close
bos.close
}
}
}