019-007-006
try-with-resourcesの基本
初級
問題説明
try-with-resourcesの基本
この問題では: AutoCloseableを実装したSimpleResourceクラスを作成し、try-with-resources文でリソースが自動クローズされる動作を確認するプログラムを作成します。
学習目標: try-with-resources文を使って自動的にリソースを解放する方法を理解する
概要
AutoCloseableを実装したSimpleResourceクラスを作成し、try-with-resources文で自動クローズされることを確認します。
仕様
SimpleResourceクラス: AutoCloseableを実装- コンストラクタで "Resource created" を出力
doWork(): "Working..." を出力close(): "Resource automatically closed" を出力
mainメソッドでtry-with-resources文を使用
出力形式
Resource created
Working...
Resource automatically closed
