A nice blog post by Edwin Dalorzo gives an essential guide to the Java 8 Optional objects. However, Optional as a value-based class implies each time an object is created to wrap the return result. This may kill the performance for a similar reason like autoboxing when a method returning an Optional result is invoked repeatedly. The following test cases evaluate the performance overhead.
- testNumberNull(): 1000 to 1400us
- testNumberOptional(): 2000 to 4000us or more
No comments:
Post a Comment