I suspect the sample code :
Code:
((Ethernet) ethernet.get(1)).avgNor = 99;
is not where the error is.
It indicates that avgNor is a numeric and also a public member
of the Ethernet class, if the above compiles then the error is elsewhere.
Code:
import java.util.*;
class IntClass {
public int value=0;
public IntClass (int value) {
this.value=value;
}
}
public class Stuff {
ArrayList list=new ArrayList();
public Stuff() {
for (int i=0; i<10; i++) {
list.add(new IntClass(i));
}
for (int i=0; i<list.size(); i++) {
System.out.print( ((IntClass)list.get(i)).value+" ");
}
System.out.println("");
((IntClass)list.get(5)).value=200; // works like a dream
for (int i=0; i<list.size(); i++) {
System.out.print( ((IntClass)list.get(i)).value+" ");
}
}
public static void main(String[] args) {
Stuff stuff1 = new Stuff();
}
}
Output:
Code:
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 200 6 7 8 9
The get method of ArrayList does not give a copy of anything
else but the object address .
Bookmarks