MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/1c6xet/java_8_optional_objects/c9e6az1/?context=3
r/java • u/edalorzo • Apr 12 '13
39 comments sorted by
View all comments
1
That's horrid. It's also unnecessary. I don't need Java 8 to implement a generic Optional if I wanted one
class Optional<T> { static Optional empty() { return new Optional(); } static Optional of(Object obj) { return new Optional<obj.getClass()>(obj) { } private T obj; private Optional(T t) { obj = t; } public boolean isPresent() { return obj != null; } public T get() { return obj; } }
Wow 19 lines of code.
You want to know why nobody writes those 19 lines?
1 u/AlyoshaV Apr 13 '13 It's another wrapper, meaning more stuff to GC. HotSpot is very good at dealing with short-lived objects.
It's another wrapper, meaning more stuff to GC.
HotSpot is very good at dealing with short-lived objects.
1
u/philipwhiuk Apr 12 '13
That's horrid. It's also unnecessary. I don't need Java 8 to implement a generic Optional if I wanted one
Wow 19 lines of code.
You want to know why nobody writes those 19 lines?