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()不是怎么用的,如果我想返回一个特定位置的元素,怎么办

解决方案 »

  1.   

    应该是你没有引入Class NeighborInfo的缘故!
      

  2.   

    Wired problem:if u didn't import NeighborInfo, then this code "public LinkedList <NeighborInfo> path = new LinkedList <NeighborInfo>(); " would has compiler error...
      

  3.   

    public LinkedList <NeighborInfo> path = new LinkedList <NeighborInfo>(); int index = path.indexOf(my_neighbor_info); 
    if (index != -1){ 
                    NeighborInfo next_hop =path.get(index-1);     
                    } 
    不会是这个字符的问题吧?
      

  4.   

    虽然不可能,还是改成这样试试:
     NeighborInfo next_hop = (NeighborInfo)path.get(index-1); 
      

  5.   

    多谢回复。
    不好意思,回复完了。。
    我查到什么问题了,原现我的代码定义的时候使用的是
    public LinkedList path = new LinkedList ()
    而不是:
    public LinkedList <NeighborInfo> path = new LinkedList <NeighborInfo>(); 
    所以报错。。我在提问的时候,用的是另一个类的定义,用后者就好了。。
    Mr_JavaBean,justinavril说的应该就是理由了。。谢谢大家。。
      

  6.   


    It's OK, just give us s...^_^...
      

  7.   

    看这个简单示例,你就明白了
    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);
    }
    }