Thank you for your reply
 
It returns novick.urlprog.CHyperlink  which is the name of the class, however when i do
if (instanceof novick.urlprog.CHyperlink)
the condition fails
 
this code
 
    if (obj instanceof novick.urlprog.CHyperlink)
    {
                link = (CHyperlink) obj;
                out.print("<br> " + link.GetHTML());
    }
    else
    {
          out.print("<br> " + obj.getClass().getName() );
    }
 
returns
 
novick.urlprog.CHyperlink
 
for each object in the vector
which seems impossible because the the name of the class is the same as what i tested for in the if statement!
 
any ideas?
----- Original Message -----
Sent: Friday, April 27, 2001 3:46 PM
Subject: RE: Objects in Vector are loosing type

What do you get if you call getClass().getName()  on the obj at the point you are getting the items back
out of the vector?
-----Original Message-----
From: Ivan [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 5:14 PM
To: [EMAIL PROTECTED]
Subject: Objects in Vector are loosing type

Does anyone know what is going on with the this weird problem?
 
I have a class named CHyperklink
 
I putting a vector into a session object and then adding CHyperlink objects to the vector.
 
When I retrieve the vector (with no problem) from the session object, I can cast the objects back to CHyperlinks if do it in the same servlet that put the objects in the vector.
 
If i retrieve the objects from the vector from a diffrent servlet than the one the put the objects into the vector, they all come out of the vector but they are not instanceof CHyperlink anymore and I cannot cast them back to CHyperlink.
 
When i call tostring() on the objects in the vector i get output indicating that they are still CHyperlinks.
 
I am stuck because i cant cast back to the CHyperlink and call the appropriate methods.  Does anyone know what is happending?
 
 
Here is output for tostring calls on objects in vector
 
novick.urlprog.CHyperlink@f11e4598
novick.urlprog.CHyperlink@97064598
novick.urlprog.CHyperlink@942a4598
novick.urlprog.CHyperlink@909e4598
novick.urlprog.CHyperlink@9c5a4598
 
Here is code for inserting vector
 
           CHyperlink hlink;
            hlink = new CHyperlink(address, description, name);
            // create hyperlink object
 
            HttpSession session = request.getSession();
            // get session
 
            Vector urls = (Vector) session.getAttribute("vector");
            // get vector from session
 
            if (urls == null)
            // vector does not exist yet
            {
                  urls = new Vector();
                  // create new vector
 
                  session.setAttribute("vector",urls);
                  // adds urls vector to session if not already there
            }
 
            urls.add(hlink);
            // add the hyperlink to the vector
 
here is code for retrieving vector
 
            HttpSession session = request.getSession();
 
            Vector v2 = (Vector) session.getAttribute("vector");
            // get vector from session
 
            Object obj;
            CHyperlink link;
            // temp variables
 
             if ( v2 != null)
             {
                   out.print("Got the vector");
 
                   for (int i = 0 ; i < v2.size() ; ++i)
                   {
                        obj = v2.get(i);
 
                        if (obj instanceof novick.urlprog.CHyperlink)
                        {
                              link = (CHyperlink) obj;
                              out.print("<br> " + link.GetHTML());
                        }
                       
                        else
                        {
                              out.print("<br> " + obj.toString() );
                        }
               }
  }
 

Reply via email to