tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Harper" <rob...@iat-cti.com>
Subject RE: Bizzare bug with my class and sharing values between different instances
Date Fri, 06 Aug 2004 21:09:04 GMT
The problem is that your data members are static. That means that for each
instance of the class, they all point to the same data member.

Robert S. Harper
801.265.8800 ex. 255
> -----Original Message-----
> From: Thomas Joseph Olaes [mailto:thomas.olaes@gmail.com]
> Sent: Friday, August 06, 2004 3:05 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Bizzare bug with my class and sharing values between different
> instances
> 
> Hello, list!
> 
> I am currently busting my brain over this problem... I have the following
> class:
> 
> package net.olaes;
> 
> import java.lang.String;
> 
> public class NumAndString {
>   private static int iNum;
>   private static String sString;
> 
>   public NumAndString(int iNum, String sString){
>     this.iNum = iNum;
>     this.sString = sString;
>   }
> 
>   public int getNum(){
>     return this.iNum;
>   }
> 
>   public String getString(){
>     return this.sString;
>   }
> }
> 
> When I try to do the following in my JSP:
> 
> Vector v = new Vector();
> v.add(new NumAndString(1, "a"));
> v.add(new NumAndString(2, "b"));
> v.add(new NumAndString(3, "c"));
> 
> Iterator i = v.iterator();
> while(i.hasNext()){
>   NumAndString nasThisOne = (NumAndString) i.next();
>   out.println(nasThisOne.getNum());
>   out.println(nasThisOne.getString());
> }
> 
> I get:
> 
> 3
> c
> 3
> c
> 3
> c
> 
> I don't understand what I'm doing wrong, my gut says to check my class
> definition, but I don't even know how to google up this problem
> because I've never seen it before.
> 
> Anywho, I'll keep checking the net for my problem, but if anyone has a
> quickie solution to my class up above, please help.
> 
> Thank you very much for your time and assistance in advance.
> 
> -TJ
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message