首页 \ 问答 \ Java泛型PECS(Java generics PECS)

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 ...
  • 像(_[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 ...
  • 尝试这个: 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)); } 很多人都没有意识到,在比赛之后捕获的文本可以在比赛之后被引用,就像任何其他捕获一样。 在这种情况下,捕捉是“整体”匹配的超集,这尤其违反直觉。 事实上,即使正则表达式作为一个整体 ...
  • 我最喜欢这样做的方法很简单: str = ''; 这将为您提供一串图像标签。 如果你想在jQuery中这样做,比如: (".IT_Icon").each(function(){ var $this = $(this); $this.html(''); }); 你想要一个字符串吗? 修改HTML? My favorite way to ...
  • 如果你想导入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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。