任何类型的Java泛型<?>(Java Generics With Any Type >)
我正在尝试用Java编写一个方法,该方法能够将自定义Key对象添加到数组中,或者更改数组中已存在的键(如果有)。 但是,我似乎无法让它发挥作用。 键将使用的类型主要是String和Integer,但我的通用方法似乎不起作用。
setValue()方法将T作为参数类型,getValue()返回T.
public void set(Key<?> key) { for (int i = 0; i < settings.size(); i++) { Key<?> k = settings.get(i); if (k.getName().equals(key.getName())) { k.setValue(key.getValue()); // Error here break; } } settings.add(key); }
错误(我正在使用Eclipse)是:
The method setValue(capture#4-of ?) in the type Key<capture#4-of ?> is not applicable for the arguments (capture#5-of ?)
I'm trying to write a method in Java that will be able to add a custom Key object to an array, or change an already existing key in the array if there is one. However, I can't seem to get it to work. The types that keys will use are primarily be String and Integer, but my universal approach doesn't seem to work.
The setValue() method has T as the parameter type, and getValue() returns T.
public void set(Key<?> key) { for (int i = 0; i < settings.size(); i++) { Key<?> k = settings.get(i); if (k.getName().equals(key.getName())) { k.setValue(key.getValue()); // Error here break; } } settings.add(key); }
The error (I'm using Eclipse) is:
The method setValue(capture#4-of ?) in the type Key<capture#4-of ?> is not applicable for the arguments (capture#5-of ?)
原文:https://stackoverflow.com/questions/22391964
最满意答案
您可以在菜单后面使用透明图层覆盖整个页面(操作css z-index)
在此图层上,您将添加一个单击事件处理程序,该处理程序将隐藏菜单并更改箭头并“display:none;” 本身。 菜单下拉列表必须在选中时“显示:阻止”它
看一下bootstrap如何用它的模态来处理它: http : //getbootstrap.com/javascript/#modals
You could use a transparent layer behind your menu that would cover the whole page (manipuling the css z-index)
On this layer you would add a click event handler that would hide the menu and change the arrow and "display:none;" itself. the menu dropdown would have to "display:block" it back when selected
have a look at how bootstrap handles it with its modals : http://getbootstrap.com/javascript/#modals
相关问答
更多-
试试下面的代码, $(document).mousedown(function(){ if($('.cd-dropdown.cd-active').length){ $('.cd-dropdown span').trigger('click'); }else{} }); Try the below code, $(document).mousedown(function(){ if($('.cd-dropdown.cd-active').length){ $('.cd-dropdown span').tr ...
-
Jquery:单击菜单外部后,下拉菜单不会消失(Jquery: drop down menu wont disappear after clicking outside of menu)[2022-08-27]
将单击事件绑定到html以捕获所做的任何单击,并使其隐藏菜单 $("html").click(function() { menu.find('.active').removeClass('active'); }); 然后使用.stopPropagation();覆盖菜单上的click事件.stopPropagation(); menu.find('ul li > a').bind('click', function (event) { event.stopPropagation(); 小提琴: ... -
只需切换打开菜单的ID即可。 一种方法, onclick ,可以完成所有工作。 function showmenu(elem) { // Clear any currently open menu var openMenu = document.getElementById("activeMenu"); if (openMenu) { openMenu.removeAttribute("id"); // Stop if we're just closing the cu ...
-
$('.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 ...
-
如何通过单击jquery中的另一个菜单关闭一个菜单及其图标?(How to close one menu and its icon by clicking on another menu in jquery?)[2022-11-14]
if ($('.xs-search > button > span').hasClass('icon-close-menu-cross2')) { $('.xs-search > button > span').removeClass('icon-close-menu-cross2').addClass('icon-search'); $('.sm-searchboxc input#search').hide(); $('.searchboxc').fi ... -
您可以在菜单后面使用透明图层覆盖整个页面(操作css z-index) 在此图层上,您将添加一个单击事件处理程序,该处理程序将隐藏菜单并更改箭头并“display:none;” 本身。 菜单下拉列表必须在选中时“显示:阻止”它 看一下bootstrap如何用它的模态来处理它: http : //getbootstrap.com/javascript/#modals You could use a transparent layer behind your menu that would cover the ...
-
添加一个额外的事件来实现它。 click某个菜单项时,您可以触发#menu-icon单击: $("#nav").on("click", "li", function () { $("#menu-icon").click(); //or $("#nav").slideToggle(); }); 演示: http : //jsfiddle.net/hungerpain/RtMNj/2/ Add an extra event to make it happen. You coul ...
-
看来每次在表体内右键单击时,都会创建一个新的上下文菜单实例。 相反,如果您为上下文菜单应显示的内容定义选择器,则菜单将仅显示在那里。 如果上下文菜单将显示在随机项上,则应使用类定义这些项,并且可以从该类实例化上下文菜单。 http://jsfiddle.net/azSMq/ $(function() { var menu1 = [ { 'Open Item information': { onclick: function(menuItem, ...
-
使用if ,然后使用else if function NotifierButtonClicked() { if (checked == true) { // code } else if (checked == false) { // code } } Use if and then else if function NotifierButtonClicked() { if (checked == true) { // cod ...
-
单击关闭菜单(Close the menu on click)[2022-09-01]
可以使用文档上的addEventListener()使用DOM API完成。 然后,您需要逻辑来查找单击目标是在菜单上还是在其任何元素上,或者页面上的其他位置。 isDescendent()借用了如何检查Javascript中是否有一个元素包含在另一个元素中 然后可以使用element.style.display = 'none'隐藏菜单 我会质疑不使用jQuery的动机,从长远来看,你会为自己做更多的工作...... var menu = document.querySelector("nav.nav") ...