from Java 8 One of the interesting features introduced is Optional class .Optional
Class mainly solves the problem of the infamous null pointer exception (NullPointerException) —— each Java Programmers are very aware of the exception .
In essence , This is a wrapper class with optional values , That means Optional A class can contain objects or be empty .
Optional yes Java A powerful step to realize functional programming , And help implement it in the paradigm . however Optional Obviously, the meaning of this is more than that .
Let's start with a simple use case . stay Java 8 before , Any call to an object method or property can cause NullPointerException:
package test.optional; public class School { private Teacher teacher; public
Teacher getTeacher() { return teacher; } } package test.optional; public class
Teacher { private Student student; public Student getStudent() { return
student; } }
Technology
Daily Recommendation