This is my code. I try to return object with including different parameters.
public class A{
ResponseObj responseObj = null;
public ResponseObj test(){
if(something){
responseObj = new ResponseObj("k","l");
}
else{
responseObj = new ResponseObj("x","y","z");
}
}
return responseObj;
}
Created ResponseObj class with two constructors.
public class ResponseObj{
String a;
String b;
String c;
String d;
public ResponseObj(String a, String b){
this.a = a;
this.b = b;
}
public ResponseObj(String a, String b,String c){
this.a = a;
this.b = b;
this.c = c;
}
}
By if condition pass,
a:"k",
b:"l",
c:null,
d:null
By else condition pass,
a:"x",
b:"y",
c:"z",
d:null
But I need to remove null values from the output
Outputs
Call if condition,
a:"k",
b:"l",
Call else condition,
a:"x",
b:"y",
c:"z"
If this is not correct way please inform me. Thank you