[BAEL-16045] - Moved code to core-java-exceptions

This commit is contained in:
amit2103
2019-10-27 20:45:01 +05:30
parent 7dd7cc09b0
commit 05d0730b34
4 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.baeldung.trywithresource;
public class AutoCloseableMain {
public static void main(String[] args) throws Exception {
orderOfClosingResources();
}
private static void orderOfClosingResources() throws Exception {
try (AutoCloseableResourcesFirst af = new AutoCloseableResourcesFirst();
AutoCloseableResourcesSecond as = new AutoCloseableResourcesSecond()) {
af.doSomething();
as.doSomething();
}
}
}

View File

@@ -0,0 +1,17 @@
package com.baeldung.trywithresource;
public class AutoCloseableResourcesFirst implements AutoCloseable {
public AutoCloseableResourcesFirst() {
System.out.println("Constructor -> AutoCloseableResources_First");
}
public void doSomething() {
System.out.println("Something -> AutoCloseableResources_First");
}
@Override
public void close() throws Exception {
System.out.println("Closed AutoCloseableResources_First");
}
}

View File

@@ -0,0 +1,17 @@
package com.baeldung.trywithresource;
public class AutoCloseableResourcesSecond implements AutoCloseable {
public AutoCloseableResourcesSecond() {
System.out.println("Constructor -> AutoCloseableResources_Second");
}
public void doSomething() {
System.out.println("Something -> AutoCloseableResources_Second");
}
@Override
public void close() throws Exception {
System.out.println("Closed AutoCloseableResources_Second");
}
}

View File

@@ -0,0 +1,8 @@
package com.baeldung.trywithresource;
public class MyResource implements AutoCloseable {
@Override
public void close() throws Exception {
System.out.println("Closed MyResource");
}
}