What’s the difference between these two methods: Optional.flatMap() and Optional.map()? An example would be appreciated. 8 Answers 8
I am trying to understand the difference between the Optional<T>.orElse() and Optional<T>.orElseGet() methods. The description for the orElse() method is “Return the value if present, otherwise return other.” While,...
From Apple’s documentation: You can use if and let together to work with values that might be missing. These values are represented as optionals. An optional value either contains...
When using the Java 8 Optional class, there are two ways in which a value can be wrapped in an optional. String foobar = <value or null>; Optional.of(foobar); //...
This question already has answers here: Is it possible to have placeholders in strings.xml for runtime values? (14 answers) Closed 4 years ago. In my Android app I’am going...
In Java 8, I want to do something to an Optional object if it is present, and do another thing if it is not present. if (opt.isPresent()) { System.out.println("found");...
Having been using Java 8 now for 6+ months or so, I’m pretty happy with the new API changes. One area I’m still not confident in is when to...
Optional type introduced in Java 8 is a new thing for many developers. Is a getter method returning Optional<Foo> type in place of the classic Foo a good practice?...
Why would you create a “Implicitly Unwrapped Optional” vs creating just a regular variable or constant? If you know that it can be successfully unwrapped then why create an...
The Swift Programming Language guide has the following example: class Person { let name: String init(name: String) { self.name = name } var apartment: Apartment? deinit { println("\(name) is...