22
33public class Response {
44
5- private boolean isSuccessful ;
6- private Exception errorCause ;
7- private Object responseObject ;
5+ private final boolean isSuccessful ;
6+ private final Exception errorCause ;
7+ private final Object responseObject ;
8+ private final Object [] responseObjectAsArray ;
89
9- public Response (Exception errorCause ) {
10+ public Response (final Exception errorCause ) {
1011 this .isSuccessful = false ;
1112 this .errorCause = errorCause ;
1213 this .responseObject = null ;
14+ this .responseObjectAsArray = new Object [0 ];
1315 }
1416
15- public Response (Object responseObject ) {
17+ public Response (final Object responseObject ) {
1618 this .isSuccessful = true ;
1719 this .errorCause = null ;
1820 this .responseObject = responseObject ;
21+ if (responseObject instanceof Object []) {
22+ this .responseObjectAsArray = (Object []) responseObject ;
23+ } else {
24+ this .responseObjectAsArray = new Object [] { responseObject };
25+ }
1926 }
2027
2128 public boolean isSuccessful () {
@@ -31,10 +38,6 @@ public Object getResponseObject() {
3138 }
3239
3340 public Object [] getResponseObjectAsArray () {
34- if (responseObject instanceof Object []) {
35- return (Object []) responseObject ;
36- } else {
37- return new Object [] { responseObject };
38- }
41+ return responseObjectAsArray ;
3942 }
4043}
0 commit comments