mercredi 13 octobre 2021

Can we have two setters in a pojo?

I have a setter that converts a string to byte[] and one simple setter which just sets the value. My question here is, is it a good practice to have two setters in a POJO? I can't find any workaround :(

Example:

byte[] a;

//Case 1: Where we recieve parameter as a string and convert it to byte array and set it to a; 
public void setA(String aString){
this.a=convertTobyteArray(aString);
}

//Case 2: Where we receive parameter as a byte array where conversion is not required and we directly assign it to a
public void setA(byte[] a){
this.a=a;
}

Aucun commentaire:

Enregistrer un commentaire