小编aea*_*ron的帖子

括号围绕数据类型?

我是一名初学程序员,在我的教科书中遇到过这个问题:

public boolean equals(DataElement otherElement)
{
    IntElement temp = (IntElement) otherElement;            
    return (num == temp.num);
}
Run Code Online (Sandbox Code Playgroud)

IntElement是.的子类DataElement.num是一个存储链表值的int.

(IntElement)之后的目的是temp =?什么IntElement temp = otherElement?而且,一般来说,将数据类型放在括号中的是什么呢?

java

9
推荐指数
1
解决办法
4884
查看次数

从ArrayList <String []>转换为Collection <Object []>?

我有一个方法必须返回一个数组集合.(这是JUnit中的参数化测试.)实际上我只需要返回三个字符串,但它们需要在一个数组集合中.这是我的方法:

public static Collection<Object[]> browserList() {
    String[] firefox = { "firefox" };
    String[] chrome = { "chrome" };
    String[] ie = { "ie" };
    ArrayList<String[]> list = new ArrayList<String[]>(3);
    list.add(firefox);
    list.add(chrome);
    list.add(ie);
    return list;
}
Run Code Online (Sandbox Code Playgroud)

这给出了一个错误:Type mismatch: cannot convert from ArrayList<String[]> to Collection<Object[]>.

所以真的有两个问题:(a)这有什么问题,考虑到这ArrayList是一个实现CollectionString从中衍生而来Object; (b)我该如何解决?

谢谢你的帮助.

java junit junit4

4
推荐指数
1
解决办法
4353
查看次数

标签 统计

java ×2

junit ×1

junit4 ×1