added a little helper method for processing a closeable object which then makes sure the resource is closed (like the try-with-resource extension in Java 7)

This commit is contained in:
James Strachan
2011-12-21 10:09:55 +00:00
parent 914b5487b4
commit 232d161e99
3 changed files with 70 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
Hello
World
+31
View File
@@ -0,0 +1,31 @@
namespace test.collections
import std.test.*
import std.io.*
import std.util.*
import java.io.*
class IoTest() : TestSupport() {
val file = File("test/HelloWorld.txt")
fun testUse() {
val list = arrayList<String>()
val reader = FileReader(file).buffered()
reader.close()
/**
TODO compiler error?
reader.use<BufferedReader,Unit>{
val line = it.readLine()
if (line != null) {
list.add(line)
}
}
assertEquals(arrayList("Hello", "World"), list)
*/
}
}