Live data from Hacker News

Garbage collection with Automatic Resource Management in Java 7

javawithswaranga.blogspot.com

1–10 of 21 posts

Re: Garbage collection with Automatic Resource Management in Java 7

#2
It's a much needed cleanup of something that's always resulted in clutter in my code. C# has had this feature for over a decade. Nice to see Java adding this since I have a lot of Java code to maintain. Like a lot of Java devs we're switching over to Scala for new projects and using vanilla Java for legacy code. Automatic resource management can be implemented trivially in Scala without the need for a new language feature to support it. Structural subtyping is awesome!

Re: Garbage collection with Automatic Resource Management in Java 7

#4

It's a much needed cleanup of something that's always resulted in clutter in my code. C# has had this feature for over a decade. Nice to see Java adding this since I have a lot of Java code to maintain. Like a lot of Java devs we're switching over to Scala for new projects and using vanilla Java for legacy code. Automatic resource management can be implemented trivially in Scala without the need for a new language fe…

How does structural subtyping help you implement automatic resource management?

Re: Garbage collection with Automatic Resource Management in Java 7

#6
post #4

It's a much needed cleanup of something that's always resulted in clutter in my code. C# has had this feature for over a decade. Nice to see Java adding this since I have a lot of Java code to maintain. Like a lot of Java devs we're switching over to Scala for new projects and using vanilla Java for legacy code. Automatic resource management can be implemented trivially in Scala without the need for a new language fe…

How does structural subtyping help you implement automatic resource management?

I can define a resource management method which accepts any object which belongs to a class that provides a close method irrespective of whether that class implements close as part of an an interface or not.

Re: Garbage collection with Automatic Resource Management in Java 7

#9
post #4

Earlier quoted context omitted.

How does structural subtyping help you implement automatic resource management?

I can define a resource management method which accepts any object which belongs to a class that provides a close method irrespective of whether that class implements close as part of an an interface or not.

Rough example below, partially taken from a book I have on Scala.

//define it like this: def using[T S) = { val result = operation(obj) obj.close() result }

//use it like this: val writer = new FunkyWriter using(writer) { writer.write("outputting some data") }

ARM was therefore possible in Scala before the Closable interface was even added to the Java libs.

Post reply on HN