Scala-ARM for class members?

168 Views Asked by At

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
    }
  }
}
1

There are 1 best solutions below

6
cchantep On BEST ANSWER

NoSuchMethodError is a compilation/runtime difference error. You compile succesfully against Scal ARM, but this one is not found (or at least not found in same version) during runtime.