中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

淮南北京網站建設新網站如何推廣

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

在這里插入圖片描述

屬于Java7的新特性。
經常會用try-catch來捕獲有可能拋出異常的代碼。如果其中還涉及到資源的使用的話,最后在finally塊中顯示的釋放掉有可能被占用的資源。
但是如果資源類已經實現了AutoCloseable這個接口的話,可以在try()括號中可以寫操作資源的語句(IO操作),會在程序塊結束時**自動釋放掉占用的資源**,不用再在finally塊中手動釋放了。

例子:
沒使用該特性

如果要釋放的資源多得話,判斷加catch占得篇幅大,不美觀也不精簡
在這里插入圖片描述用了這個特性后代碼可以精簡些
在這里插入圖片描述
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知識大全

jenkov.com

http://www.risenshineclean.com/news/34410.html

相關文章:

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