Posts

Showing posts from April, 2023

Java 8

Image
  we identified two problems. Data Missing Instead o dealing with the problem,  we r escaping from the problem by just putting !=null W e came up with two solutions Returning the Optional<Dept> in the getter method (best Case) Handle while processing the stream (alternative solution) by providing some default values. When and Where to Declare Optional ? Method Return Type When to not use Optional<> ? instance Variables of value object. Reason: During the Serialization it will throw the exception. sample output as follows                     b. writing Optional to JSON produces undesired results                   c. Avoid using Optional as a method parameter          5. How we return a default value ?                     using orElse() or orElseGet()  as we see in the code