Click here to watch in Youtube :
https://www.youtube.com/watch?v=TQba1G_Pkr4&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Exception handling (Try with resources-custom AutoClosable implementation) |
Java Tutorial : Java Exception handling (Try with resources-custom AutoClosable implementation) |
public class MyBufferedReader implements AutoCloseable { public void read() { System.out.println("read method is called..."); } @Override public void close() throws Exception { System.out.println("close method is called..."); } }
TryWithResourcesDemo.javapublic class TryWithResourcesDemo { public static void main(String[] args) throws Exception { try (MyBufferedReader myBufferedReader = new MyBufferedReader()) { myBufferedReader.read(); } } }
read method is called... close method is called...
https://sites.google.com/site/javaee4321/java/ExceptionDemo_Custom_AutoClosable_impl_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ExceptionDemo_Custom_AutoClosable_impl_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/4babce59a384cb4ab41f12b03cd7d11227a4b186/BasicJava/ExceptionDemo_Custom_AutoClosable_impl_App/?at=master
See also:
No comments:
Post a Comment