not able to access class fields
I have a class like :
class CustomerData{
int ssn;
int homePhone;
int officePhone;
String ProductCode;
String product;
String sameAsPrev开发者_如何学JAVA=null;
String ProductDescription;
String ForwardProduct;
// set/get methods }
there is a Controller Class:
------------------------------
in a method customerInfoContinue() {
customerData customerData=new CustomerData();
customerData.setSsn(customerForm.getSsn);
customerData.setHomePhone(cuatomerForm.getHomePhone());
.
.
.
.
customerData.setProductDescription((String)session.getAttribute("Product Description"));
customerData.setProductDescription((String)session.getAttribute("Forward Product"));
after setting values Map has been created like this:
Map<String,CustomerData> customerDataMap=new LinkedHashMap<String,CustomerData>();
//setting product code as key
CustomerDataMap.put(customerForm.getProductCode,customerData);
}
and in everyWhere in Jsp they have used this CustomerDataMap.
Now the Problem is : I have to change CustomerData Class with Customer class.
but in Customer class 2 fields ProductDescription and ForwardProduct are not available. also customer class is a jar file so i can't change the fields.
pls advice something how to get rid of this problem..
If you cannot change the classes in the jar but can change the controller you can probably create your own Customer class which extends the CustomerData class. But that all of course depends on where this class is used.
public class Customer extends CustomerData {
private String ProductDescription;
private String ForwardProduct;
// add getters and setters
}
You cannot dynamically add fields to an existing class. You will need to edit the source code, or let the upstream developers know what you need changed.
精彩评论