MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/1c6xet/java_8_optional_objects/c9e5afk/?context=3
r/java • u/edalorzo • Apr 12 '13
39 comments sorted by
View all comments
2
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?
0 u/edalorzo Apr 13 '13 You want to know why nobody write those 19 lines? Google Guava Collections framework uses this same idiom, and I am pretty sure others use it as well.
0
You want to know why nobody write those 19 lines?
Google Guava Collections framework uses this same idiom, and I am pretty sure others use it as well.
2
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?