I'm fairly new to Java, and I'm having some troubles with a vector. Say I have something like this:
It's all fine up to the last line, which gives me an error, telling me it can't find variable test.
Obviously I want each element of vector v to be an instance of blah, but why can't I reference instance variables this way? It works fine using an array instead of a vector, but that doesn't suit my purposes, unless I rework a bunch of stuff.
Code:
class Blah {
public int test;
public Blah() {
test=3;
}
}
Vector v = new Vector(0,1);
v.addElement(new Blah());
int t = v.elementAt(0).test;
}
It's all fine up to the last line, which gives me an error, telling me it can't find variable test.
Obviously I want each element of vector v to be an instance of blah, but why can't I reference instance variables this way? It works fine using an array instead of a vector, but that doesn't suit my purposes, unless I rework a bunch of stuff.