Merge pull request #7465 from amit2103/BAEL-16045-15
[BAEL-16045] - Check Article Code Matches GitHub for https://www.bael…
This commit is contained in:
commit
108840fcb4
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.trywithresource;
|
||||
|
||||
public class MyResource implements AutoCloseable {
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
System.out.println("Closed MyResource");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue