try-with-resource是否有可能无法关闭资源?(Is it possible for try-with-resource to fail to close resources?)
根据Oracle文档
try-with-resources语句是一个声明一个或多个资源的try语句。 资源是一个对象,必须在程序完成后关闭它。 try-with-resources语句确保在语句结束时关闭每个资源。 实现java.lang.AutoCloseable的任何对象(包括实现java.io.Closeable的所有对象)都可以用作资源
如果资源没有实现AutoCloseable,它不能在try块中声明,它必须在body部分声明并且必须在finally块中显式关闭。 try-with-resource是否有可能无法清理资源,除非您使用不正确的习惯用法,如果有嵌套资源并且close()调用对底层资源不是幂等的? 我理解的是try-with-resource只能确保在场景后面调用close(),但如果close本身不关闭底层资源,try-with-resource将无法清理资源。 有没有人有相反的观点或更多的澄清?
As per Oracle documentation
The try-with-resources statement is a try statement that declares one or more resources. A resource is as an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource
If a resource does not implement AutoCloseable it cannot be declared within try block, it has to be declared in the body part & has to be explicitly closed in finally block. Is it possible for try-with-resource to fail to clean up resources unless you use the idiom incorrectly like if there are nested resources & close() call is not idempotent for the underlying resource? What I understand is try-with-resource only ensures close() getting called behind the scene, but if close itself does not close underlying resources try-with-resource will remain ineffective to clean-up resources. Does anyone have a contrary view or more clarification?
原文:https://stackoverflow.com/questions/36831233
最满意答案
您可以依赖于相同的href值,并根据该值确定元素
$('.tabs-menu a[href="' + href + '"]').parent().addClass("current"); $('.tabs-menu a').not('a[href="' + href + '"]').parent().removeClass("current");
这是一个工作小提琴
You can lean on the same href value, and identify the elements based on that, something like
$('.tabs-menu a[href="' + href + '"]').parent().addClass("current"); $('.tabs-menu a').not('a[href="' + href + '"]').parent().removeClass("current");
here is a working fiddle
相关问答
更多-
给你写了一个,看是不是理想中的效果,不对可以改: ps:看的时候记得改一下引用jquery路径 ---------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >& ...
-
这是您的问题的快速解决方案。 我手动创建select元素,并将更改委托给实际链接。 因此,无论您使用select导航,都会执行任何代码。 我在开始时创建了select元素,并使用媒体查询根据浏览器宽度显示/隐藏它 CSS #sidebar > .tabs-menu{display:block} #sidebar > select{display:none;} @media (max-width:400px){ #sidebar > .tabs-menu{display:none} #sid ...
-
您可以依赖于相同的href值,并根据该值确定元素 $('.tabs-menu a[href="' + href + '"]').parent().addClass("current"); $('.tabs-menu a').not('a[href="' + href + '"]').parent().removeClass("current"); 这是一个工作小提琴 http://jsfiddle.net/9mqf8ar0/2/ You can lean on the same href value, a ...
-
$('.tab_contents').hide(); var count = 0; $('.tab').click(function() { count++; //increment count everytime it is clicked var target = $(this.rel); $('.tab_contents').not(target).hide(); target.slideToggle(100); $('#tabs_container ...
-
您可以将onfocus添加到这些字段,因此如果通过“tab”或单击来聚焦该输入,则将触发此事件。 $("#table_appl,#table_enfr,#table_det01,#table_det02,#table_det03,#table_det04,#table_det05,#table_datais").on( "focus", "input:text", function( event ) {}) you could add onfocus to those fields, so if that ...
-
Jquery帮助左选项卡菜单(Jquery help with left tab menu)[2023-11-15]
当你说$('。leftKanji')时,你引用该类的所有元素。 下面的代码将获取作为.leftTab元素的子元素的元素。 您可以将.children()更改为jQuery api中的任何一个遍历选择器,但我使用那个作为示例。 但重要的是使用$(this),因为它与悬停的元素相对应。 $(document).ready(function(){ $('.leftTab').hover( function(){ $(this).children(.leftKanji').css('displa ... -
jquery tab cookie ...?(jquery tab cookie …?)[2023-01-06]
您可以查看.appendTo()的JSON Cookie解决方案。 它将提供一种存储和检索最后活动选项卡的简单方法。 用法记录如下: $.cookie( string key, mixed value [, hash options ] ) 因此,您可以存储活动选项卡的索引: $.cookie( 'activeTab', '3' ); 然后在页面加载时检索它: $.cookie( 'activeTab' ); //returns the set value 那么让我们来看看如何实现它: $("#nav ... -
Jquery选项卡菜单滚动箭头(Jquery Tab menu scroll arrows)[2023-08-13]
有很多插件可用于此: 这是一个例子 演示: http : //jsfiddle.net/LtmA5/1/ 资源: http://jquery.aamirafridi.com/jst/ There are numerous plugins available for this: Here's one example DEMO: http://jsfiddle.net/LtmA5/1/ Source: http://jquery.aamirafridi.com/jst/ -
菜单上的jquery活动选项卡(jquery active tab on menu)[2021-04-01]
看来你必须使用jquery.cookie才能做到这一点。 我修改了你的代码如下: $(document).ready(function() { var cookieName = 'tab_of'; var cookieTab = 'tab'; var cookieOptions = {expires: 7, path: '/'}; $("#content div").hide(); //Hide all content $("#" + $.cook ... -
如何制作标签菜单(How to make a tab menu)[2024-02-10]
请改用.show() & hide() 。 例: ul{height: 40px;} li{float: left;padding: 5px;background-color: #ccc;color:#333;margin-left: 10px;list-style: none;} .panel{height:100px;width: 800px;margin: 0 auto 10px;background-color: #ccc;/*display: none;*/} .sh ...