Accessing a method inside of an object that is stored in a vector...

From: da Vinci (blank_at_blank.com)
Date: 12/05/04


Date: Sun, 05 Dec 2004 01:22:53 GMT

I have been trying to post to .help all day but nothing is going
through. Will try it here and hope it does....

I am trying to access a getData() method that simply returns a stored
integer value from an object that is stored in a vector. I have tried
to do this but cannot get the notation correct. I tried google groups
and the only thing I got from there was to pull the object from the
vector into a temperary object. That didnt work.

So, here is the code I have so far of making the temp object and
making sure it is actually pulling one out. I still connot figure out
how to access the getData() method.

Any hints are appreciated.

import java.util.Vector;

public class StackUser
{

        public static void main(String argv[])
        {

                Vector vector = new Vector();

                for (int i = 0; i < 100; i++)
                        vector.add(i, new StackNode());

                        System.out.println(vector.get(0));

                        Object tobj = vector.get(0);

                        System.out.println(tobj);

        }
}

public class StackNode
{

        private int value = 0;

        public StackNode()
        {
                value = (int)(Math.random());
        }

        public int getData()
        {
                return value;
        }

}



Relevant Pages

  • Re: return object of an unknown type
    ... but a version where getdata takes no ... public class MyClass2: MyMainClass ... public override Control GetData() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: return object of an unknown type
    ... public class MyMainClass ... public virtual TextBox GetData() ... public class MyClass2: MyMainClass ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: write read string data
    ... GetData getData1 = new GetData; ... public class GetData extends JPanel { ... and then you compare it to a String. ...
    (comp.lang.java.help)
  • Accessing a method in an object that is in a vector. (2nd Try)
    ... I have tried to make a temperary object and save each object in the ... but that didnt work. ... using a println() to check and make sure my temperary object was ... public class StackUser ...
    (comp.lang.java.help)