I need some help in trying to find out how to cast a method that is within an object which is inside a LinkedList.
Let me try to explain:
I already know that I have to use a wrapper to convert an object back into another state. The think I am confused about is how to use a method from the object. What I am doing is storing Objects called Item into a LinkedList. I have a method from Item that gets a stored variable. Heres the code for my Item class.
public class Item implements Comparable
{
private int myId;
private int myInv;
public Item(int id, int inv)
{
myId = id;
myInv = inv;
}
public int getId()
{
return myId;
}
public int getInv()
{
return myInv;
}
public int compareTo(Object otherObject)
{
Item right = (Item)otherObject;
return myId - right.myId;
}
public boolean equals(Object otherObject)
{
return compareTo(otherObject) == 0;
}
public String toString()
{
String string = (getId() + " " + getInv());
return string;
}
}
From my experience so far, Arrays with stored objects only need to method call after referencing it.
int id = myArray[index].getId()
What I tried was:
int id = myList.get(index).getId();
I knew that this aproach probably wouldn't work anyway. So right now I need someone to help me to understand how to call a method from an object within a LinkedList.
Thanks in advanced,
Lord Felix