国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

淮南北京網(wǎng)站建設(shè)新網(wǎng)站如何推廣

淮南北京網(wǎng)站建設(shè),新網(wǎng)站如何推廣,中山做網(wǎng)站排名,推薦武漢網(wǎng)站建設(shè)屬于Java7的新特性。 經(jīng)常會(huì)用try-catch來(lái)捕獲有可能拋出異常的代碼。如果其中還涉及到資源的使用的話,最后在finally塊中顯示的釋放掉有可能被占用的資源。 但是如果資源類已經(jīng)實(shí)現(xiàn)了AutoCloseable這個(gè)接口的話,可以在try()括號(hào)中可以寫操作資源的語(yǔ)句(…

在這里插入圖片描述

屬于Java7的新特性。
經(jīng)常會(huì)用try-catch來(lái)捕獲有可能拋出異常的代碼。如果其中還涉及到資源的使用的話,最后在finally塊中顯示的釋放掉有可能被占用的資源。
但是如果資源類已經(jīng)實(shí)現(xiàn)了AutoCloseable這個(gè)接口的話,可以在try()括號(hào)中可以寫操作資源的語(yǔ)句(IO操作),會(huì)在程序塊結(jié)束時(shí)**自動(dòng)釋放掉占用的資源**,不用再在finally塊中手動(dòng)釋放了。

例子:
沒使用該特性

如果要釋放的資源多得話,判斷加catch占得篇幅大,不美觀也不精簡(jiǎn)
在這里插入圖片描述用了這個(gè)特性后代碼可以精簡(jiǎn)些
在這里插入圖片描述
try-catch-finally
在這里插入圖片描述

try-with-resources
在這里插入圖片描述

在這里插入圖片描述在這里插入圖片描述在這里插入圖片描述----------------------------------------------------分割線---------------------------------------------------------------------
取自:https://jenkov.com/tutorials/java-exception-handling/try-with-resources.html
Using Multiple Resources
You can use multiple resources inside a Java try-with-resources block and have them all automatically closed. Here is an example of using multiple resources inside a try-with-resources block:
在這里插入圖片描述
This example creates two resources inside the parentheses after the try keyword. An FileInputStream and a BufferedInputStream. Both of these resources will be closed automatically when execution leaves the try block.
Closing Order
The resources declared in a Java try-with-resources construct will be closed in reverse order of the order in which they are created / listed inside the parentheses. In the example in the previous section, first the will be closed, then the FileInputStream.
Custom AutoClosable Implementations
The Java try-with-resources construct does not just work with Java’s built-in classes. You can also implement the java.lang.AutoCloseable interface in your own classes, and use them with the try-with-resources construct.

The AutoClosable interface only has a single method called close(). Here is how the interface looks:
在這里插入圖片描述
Any class that implements this interface can be used with the Java try-with-resources construct. Here is a simple example implementation:
在這里插入圖片描述
The doIt() method is not part of the AutoClosable interface. It is there because we want to be able to do something more than just closing the object.

Here is an example of how the MyAutoClosable is used with the try-with-resources construct:
在這里插入圖片描述
Here is the output printed to System.out when the method myAutoClosable() is called:
在這里插入圖片描述
As you can see, try-with-resources is a quite powerful way of making sure that resources used inside a try-catch block are closed correctly, no matter if these resources are your own creation, or Java’s built-in components.

舉例
在這里插入圖片描述

參考:
Java必須懂的try-with-resources

java知識(shí)大全

jenkov.com

http://aloenet.com.cn/news/34410.html

相關(guān)文章:

  • wap網(wǎng)站為什么沒有了沈陽(yáng)網(wǎng)絡(luò)seo公司
  • 公司網(wǎng)站打不開網(wǎng)頁(yè)搜索引擎大全
  • 濟(jì)源城鄉(xiāng)建設(shè)局網(wǎng)站營(yíng)銷推廣技巧
  • 有哪些做外貿(mào)免費(fèi)的網(wǎng)站深圳網(wǎng)站設(shè)計(jì)專家樂云seo
  • 哪些網(wǎng)站專門做康復(fù)科seo網(wǎng)站優(yōu)化排名
  • 珍島網(wǎng)站模板最近社會(huì)熱點(diǎn)新聞事件
  • 重慶知名網(wǎng)站制作公司seo推廣方法
  • 音樂網(wǎng)站的設(shè)計(jì)與開發(fā)可以免費(fèi)網(wǎng)絡(luò)推廣網(wǎng)站
  • 濟(jì)南網(wǎng)站建設(shè)優(yōu)化站長(zhǎng)申論
  • java配合什么做網(wǎng)站獨(dú)立站seo外鏈平臺(tái)
  • 國(guó)際新聞?dòng)檬裁窜浖纯粗貞cseo
  • 網(wǎng)站建設(shè)目標(biāo)怎么看廣州網(wǎng)站優(yōu)化平臺(tái)
  • 網(wǎng)站開發(fā)的時(shí)間流程seo修改器
  • 楚雄做網(wǎng)站百度推廣費(fèi)用報(bào)價(jià)單
  • 重慶綦江網(wǎng)站制作公司哪家專業(yè)最全的搜索引擎
  • 專業(yè)網(wǎng)站定制公司新開店鋪怎么做推廣
  • wordpress加載慢廣州seo優(yōu)化推廣
  • 做介紹的英文網(wǎng)站網(wǎng)站設(shè)計(jì)公司上海
  • jsp和php哪個(gè)做網(wǎng)站快百度seo是什么意思
  • 做網(wǎng)站需要多少錢西安優(yōu)化大師官網(wǎng)下載
  • 打開ecshop網(wǎng)站提示內(nèi)容溢出網(wǎng)站的推廣平臺(tái)有哪些
  • 廣州疫情防控最新消息淘寶標(biāo)題優(yōu)化網(wǎng)站
  • 廣州app定制公司百度seo收費(fèi)
  • 只做外貿(mào)的公司網(wǎng)站seo推廣公司價(jià)格
  • 公司郵箱價(jià)格免費(fèi)的seo
  • 青島鑫隆建設(shè)集團(tuán)網(wǎng)站網(wǎng)絡(luò)推廣山東
  • 網(wǎng)站建設(shè)難點(diǎn)網(wǎng)站推廣優(yōu)化設(shè)計(jì)方案
  • 蘇州園區(qū)做網(wǎng)站公司seoul是啥意思
  • 貴州安順建設(shè)主管部門網(wǎng)站百度seo網(wǎng)站優(yōu)化
  • 網(wǎng)站建設(shè) 瀏覽器兼容1688的網(wǎng)站特色