Answers for "how to initialize class object as null in java"

0

how to initialize class object as null in java

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException {
    // Note that unless except in certain cases (IoC)
    // this scenario is quite easy to avoid
    Object_DTO object_DTO = null;

    if(request.getParameter("parameter").equals("hello")) {
        object_DTO = new Object_DTO(); // here null object initialized to a new object
        object_DTO.setAttr("attr");
        ...
    } else if (request.getParameter("parameter").equals("goodbye")) {
        object_DTO = new Object_DTO();
    }

    if (object_DTO == null) {
        // Bad response
    }
}
Posted by: Guest on May-31-2021

Code answers related to "how to initialize class object as null in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language