Java to Kotlin converter: no special logic for returns in try-with-resource is needed anymore

This commit is contained in:
Valentin Kipyatkov
2014-07-09 13:27:41 +04:00
parent 2ebaab867d
commit fe46b40220
4 changed files with 4 additions and 37 deletions
@@ -1,17 +0,0 @@
//file
import java.io.*;
public class C {
int foo() {
try(InputStream stream = new FileInputStream("foo")) {
while(true) {
int c = stream.read();
if (c < 0 || c > 127) return c;
}
}
catch (IOException e) {
System.out.println(e);
return -1;
}
}
}
@@ -3,10 +3,10 @@ import java.io.*
public class C {
fun foo(): Int {
try {
return FileInputStream("foo").use { stream ->
FileInputStream("foo").use { stream ->
// reading something
val c = stream.read()
c
return c
}
} catch (e: IOException) {
System.out.println(e)
@@ -8,8 +8,8 @@ trait I {
public class C {
throws(javaClass<IOException>())
fun foo(): Int {
return FileInputStream("foo").use { stream ->
bar(object : I {
FileInputStream("foo").use { stream ->
return bar(object : I {
throws(javaClass<IOException>())
override fun doIt(stream: InputStream): Int {
return stream.available()