how to initialize class object as null in java

Solutions on MaxInterview for how to initialize class object as null in java by the best coders in the world

showing results for - "how to initialize class object as null in java"
Pia
16 Jan 2017
1protected void doPost(HttpServletRequest request, HttpServletResponse response) 
2  throws ServletException, IOException {
3    // Note that unless except in certain cases (IoC)
4    // this scenario is quite easy to avoid
5    Object_DTO object_DTO = null;
6
7    if(request.getParameter("parameter").equals("hello")) {
8        object_DTO = new Object_DTO(); // here null object initialized to a new object
9        object_DTO.setAttr("attr");
10        ...
11    } else if (request.getParameter("parameter").equals("goodbye")) {
12        object_DTO = new Object_DTO();
13    }
14
15    if (object_DTO == null) {
16        // Bad response
17    }
18}
19