Java泛型PECS(Java generics PECS)
我知道PECS是什么意思。
制作人扩展,消费者超级。
问题是我如何知道它是消费者还是生产者?
此代码也遵循“PECS”
public class Tree<T> { //List of branches for this tree private List<Tree<? super T>> branch = new ArrayList<Tree<? super T>>(); public Tree(T t){ this.t = t; } public void addBranch(Tree< ? super T> src){ branch.add(src); } public Tree<? extends T> getBranch(int branchNum){ return (Tree<? extends T>) branch.get(branchNum); } private T t; }
I know what is the meaning of PECS.
Producer Extends,Consumer Super.
the thing is how would I know if its a consumer or producer?
Also does this code follow the "PECS"
public class Tree<T> { //List of branches for this tree private List<Tree<? super T>> branch = new ArrayList<Tree<? super T>>(); public Tree(T t){ this.t = t; } public void addBranch(Tree< ? super T> src){ branch.add(src); } public Tree<? extends T> getBranch(int branchNum){ return (Tree<? extends T>) branch.get(branchNum); } private T t; }
原文:https://stackoverflow.com/questions/12197685
更新时间:2023-08-19 16:08
最满意答案
我最喜欢这样做的方法很简单:
str = '<img src="' + ary.join('"/><img src="') + '"/>';
这将为您提供一串图像标签。 如果你想在jQuery中这样做,比如:
(".IT_Icon").each(function(){ var $this = $(this); $this.html('<img src="' + $this.text() + '"/>'); });
你想要一个字符串吗? 修改HTML?
My favorite way to do this is simply:
str = '<img src="' + ary.join('"/><img src="') + '"/>';
which will give you a single string of image tags. If you want to do it in jQuery, something like:
(".IT_Icon").each(function(){ var $this = $(this); $this.html('<img src="' + $this.text() + '"/>'); });
Are you trying to get a string? amend the HTML?
相关问答
更多-
你需要 chomp @elements 在使用内容之前,只有当文本出现在@dnis的行末尾时,内容才会匹配。 使用look-behind也没有意义,你需要注意数据可能包含的任何正则表达式元字符。 你可能需要 print "$1\n" if $dn =~ /(\Q$call\E.*)/; You need to chomp @elements before you use the contents, otherwise the contents will match only if the text a ...
-
可选的正则表达式匹配?(optional regex match?)[2024-02-10]
像(_[1-3])? ? 匹配零个或一个实例。 可能是你在找什么。 Something like (_[1-3])? ? Matches zero or one instance. might be what you are looking for. -
您需要创建一个RegExp对象。 您还需要将.replace应用于字符串,并分配结果。 for (ii = 0; ii < arr.length; ii++) { str = str.replace(new Regexp('\\.' + arr[ii], 'i')); } You need to create a RegExp object. You also need to apply .replace to the string, and assign the result. for (ii ...
-
我正在使用你的$content变量: $preg1 = preg_match_all('#
([^<]+)#', $content, $name_arr); $preg2 = preg_match_all('# ([^<]+)#', $content, $val_arr); $array = array_combine($name_arr[1], $val_arr[1]); I'm using your $content variable: $preg1 = preg_match_a ... -
阵列上的正则表达式?(Regex on an array?)[2023-03-02]
尝试这个: foreach ($progress as $str) { if (preg_match_all('/\[download] (\d+\.\d)% of (\d+\.\d+\w)/', $str, $matches)) { var_dump($matches); } } Try this: foreach ($progress as $str) { if (preg_match_all('/\[download] (\d+\.\d)% of (\d+\. ... -
使用分支重置组 (?|.....)将多个捕获转换为单个捕获。 (?|\[([^\]]*)\]|\{([^\}]*)\}) 也就是说,分支重置组内的备选方案共享相同的捕获组。 DEMO Use the branch reset group (?|.....) to turn multiple captures into a single one. (?|\[([^\]]*)\]|\{([^\}]*)\}) That is, alternatives inside a branch reset group ...
-
std::regex_match和它的朋友通过迭代器工作(以及不仅是const std::string&而且是const char*重载)。 所以,是的,你绝对可以使用字符数组而不是std::string 。 我建议阅读文档。 根据您的编辑: if(regex_match(userCommand[3], userCommand[8], isNumeric)) 如果userCommand是数组,则传入两个char ,而不是指针(“iterators”)。 尝试: if(regex_match(&userCo ...
-
我不认为这是可能的与split() ,但与find()它非常简单。 只需在内部使用一个捕捉组: Matcher m = Pattern.compile("(?=(\\d\\d)).").matcher("12345"); while (m.find()) { System.out.println(m.group(1)); } 很多人都没有意识到,在比赛之后捕获的文本可以在比赛之后被引用,就像任何其他捕获一样。 在这种情况下,捕捉是“整体”匹配的超集,这尤其违反直觉。 事实上,即使正则表达式作为一个整体 ...
-
关于阵列/正则表达式的问题(Questions about Arrays / Regex)[2021-07-23]
我最喜欢这样做的方法很简单: str = ''; 这将为您提供一串图像标签。 如果你想在jQuery中这样做,比如: (".IT_Icon").each(function(){ var $this = $(this); $this.html(''); }); 你想要一个字符串吗? 修改HTML? My favorite way to ... -
正则表达式Python问题(Regex Python questions)[2022-01-05]
如果你想导入re,这是一种方式: import re thisstring = '''some text here more text findme=words15515.1515 ''' a = [t[0] for t in [re.findall(r'^findme=.*',r) for r in thisstring.split('\n')] if t] If you want to import re this is one way: import re thisstring = '''som ...