path定义:
public LinkedList<NeighborInfo> path = new LinkedList<NeighborInfo>();int index = path.indexOf(my_neighbor_info);
if (index != -1){
NeighborInfo next_hop =path.get(index-1);
}错误提示:
found : java.lang.Object
required: bamboo.router.NeighborInfo
NeighborInfo next_hop = path.get(index-1);
在LinkedList的API中,有这个成员函数
Object get(int index)
Returns the element at the specified position in this list.难道这个get()不是怎么用的,如果我想返回一个特定位置的元素,怎么办
public LinkedList<NeighborInfo> path = new LinkedList<NeighborInfo>();int index = path.indexOf(my_neighbor_info);
if (index != -1){
NeighborInfo next_hop =path.get(index-1);
}错误提示:
found : java.lang.Object
required: bamboo.router.NeighborInfo
NeighborInfo next_hop = path.get(index-1);
在LinkedList的API中,有这个成员函数
Object get(int index)
Returns the element at the specified position in this list.难道这个get()不是怎么用的,如果我想返回一个特定位置的元素,怎么办
if (index != -1){
NeighborInfo next_hop =path.get(index-1);
}
不会是这个字符的问题吧?
NeighborInfo next_hop = (NeighborInfo)path.get(index-1);
不好意思,回复完了。。
我查到什么问题了,原现我的代码定义的时候使用的是
public LinkedList path = new LinkedList ()
而不是:
public LinkedList <NeighborInfo> path = new LinkedList <NeighborInfo>();
所以报错。。我在提问的时候,用的是另一个类的定义,用后者就好了。。
Mr_JavaBean,justinavril说的应该就是理由了。。谢谢大家。。
It's OK, just give us s...^_^...
public class ToStringSample
{
String info = null;
public ToStringSample()
{
info = "This is a sample!";
}
public String toString()
{
return info;
}
public static void main(String[] args)
{
ToStringSample t = new ToStringSample();
System.out.println(t);
}
}