I am trying to assign some values to static class and it does not work as I expected. I was expecting to see different values for different classes. However, they fall into the same value because it is static??? See code snippet here:

    NewOperationResponseSimpleType[] resp=new NewOperationResponseSimpleType[3];
    NewOperationResponseSimpleType[] res1=new NewOperationResponseSimpleType[3];

    NewOperationResponseSimpleType[] res1=new NewOperationResponseSimpleType[3];
    NewOperationResponseSimpleType[] res2=new NewOperationResponseSimpleType[3];
    NewOperationResponseSimpleType[] res3=new NewOperationResponseSimpleType[3];

    for (int i=0; i<3;i++){
        res1[i]=NewOperationResponseSimpleType.resp1;
        res1[i]._value_=i+"_Value1";
        System.out.println("res1["+i+"].getValue()"+res1[i].getValue());

        res2[i]=NewOperationResponseSimpleType.resp2;
        res2[i]._value_=i+"_Value2";
        System.out.println("res2["+i+"].getValue()"+res2[i].getValue());

        res3[i]=NewOperationResponseSimpleType.resp3;
        res3[i]._value_=i+"_Value3";
        System.out.println("res3["+i+"].getValue()"+res3[i].getValue());

        resp[i].resp1=res1[i];
        System.out.println("resp["+i+"].resp1.getValue()"+resp[i].resp1.getValue());
        resp[i].resp2=res2[i];
        System.out.println("resp["+i+"].resp2.getValue()"+resp[i].resp2.getValue());
        resp[i].resp3=res3[i];
        System.out.println("resp["+i+"].resp3.getValue()"+resp[i].resp3.getValue());


    }

    for (int j=0; j<3; j++){

        System.out.println("resp["+j+"].resp1.getValue()"+resp[j].resp1.getValue());
        System.out.println("resp["+j+"].resp2.getValue()"+resp[j].resp2.getValue());
        System.out.println("resp["+j+"].resp3.getValue()"+resp[j].resp3.getValue());
    }



public class NewOperationResponseSimpleType  {

    public java.lang.String _value_;
    public  java.util.HashMap _table_ = new java.util.HashMap();

    // Constructor
    public NewOperationResponseSimpleType(java.lang.String value) {
        _value_ = value;
        _table_.put(_value_,this);
    };

    public static  final java.lang.String _resp1 = "resp1";
    public static  final java.lang.String _resp2 = "resp2";
    public  static final java.lang.String _resp3 = "resp3";
    public  static  NewOperationResponseSimpleType resp1 = new NewOperationResponseSimpleType(_resp1);
    public  static  NewOperationResponseSimpleType resp2 = new NewOperationResponseSimpleType(_resp2);
    public  static  NewOperationResponseSimpleType resp3 = new NewOperationResponseSimpleType(_resp3);
    public java.lang.String getValue() { return _value_;}
    public  NewOperationResponseSimpleType fromValue(java.lang.String value)
          throws java.lang.IllegalArgumentException {
        NewOperationResponseSimpleType enumeration = (NewOperationResponseSimpleType)
            _table_.get(value);
        if (enumeration==null) throw new java.lang.IllegalArgumentException();
        return enumeration;
    }
    public  NewOperationResponseSimpleType fromString(java.lang.String value)
          throws java.lang.IllegalArgumentException {
        return fromValue(value);
    }
    public boolean equals(java.lang.Object obj) {return (obj == this);}
    public int hashCode() { return toString().hashCode();}
    public java.lang.String toString() { return _value_;}


}

I don't see any static classes here, Do you mean static variables?
Why are you using static variables?

I was expecting to see different values

You only get different values (one per class instance) with non static variables.
With static variables all instances of a class share one variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.