Loading topic
null. This chapter shows where null comes from, why it breaks programs, and why the fixes people usually reach for don't hold up well.2 min readnull causes trouble. A method can return null, and nothing in its signature warns you. If you forget to check, your program crashes with a NullPointerException. This chapter introduces the tool Java provides for this problem.2 min readnew Optional.2 min readisPresent and isEmpty.3 min readifPresent and ifPresentOrElse.2 min readorElse and orElseGet to get a value out of an Optional. Both give you a default when the Optional is empty. They look almost the same, but they differ in one way that matters: when the default value gets made.2 min readmap and filter methods do this for you in one step, and they never touch a missing val2 min readflatMap joins such steps into one clear chain.2 min readOptional<T> holds an object that may or may not be there. Java also has three smaller cousins for plain numbers: OptionalInt, OptionalLong, and OptionalDouble. This chapter shows what they are, why they exist, and how to read a value out of them.2 min readOptional, called or and stream. Both help when you have more than one Optional to work with. or lets you try a backup source when the first one is empty. stream lets you mix Optionals into a stream pipeline.2 min readOptional methods. This chapter covers where Optional belongs and where it does not. An anti-pattern is a common habit that looks reasonable but causes problems. Avoiding a few of them keeps your code clean and safe.2 min read