Answer by Steve B. for Why should Java 8's Optional not be used in arguments
This seems a bit silly to me, but the only reason I can think of is that object arguments in method parameters already are optional in a way - they can be null. Therefore forcing someone to take an...
View ArticleAnswer by llogiq for Why should Java 8's Optional not be used in arguments
This advice is a variant of the "be as unspecific as possible regarding inputs and as specific as possible regarding outputs" rule of thumb.Usually if you have a method that takes a plain non-null...
View ArticleAnswer by Joop Eggen for Why should Java 8's Optional not be used in arguments
Oh, those coding styles are to be taken with a bit of salt.(+) Passing an Optional result to another method, without any semantic analysis; leaving that to the method, is quite alright.(-) Using...
View ArticleAnswer by Makoto for Why should Java 8's Optional not be used in arguments
The pattern with Optional is for one to avoid returningnull. It's still perfectly possible to pass in null to a method.While these aren't really official yet, you can use JSR-308 style annotations to...
View ArticleAnswer by Macchiatow for Why should Java 8's Optional not be used in arguments
I believe the reson of being is you have to first check whether or not Optional is null itself and then try to evaluate value it wraps. Too many unnecessary validations.
View ArticleAnswer by Danil Gaponov for Why should Java 8's Optional not be used in...
I think that is because you usually write your functions to manipulate data, and then lift it to Optional using map and similar functions. This adds the default Optional behavior to it.Of course, there...
View ArticleWhy should Java 8's Optional not be used in arguments
I've read on many Web sites Optional should be used as a return type only, and not used in method arguments. I'm struggling to find a logical reason why. For example I have a piece of logic which has 2...
View ArticleAnswer by Marko for Why should Java 8's Optional not be used in arguments
In case you want to have an Optional argument in your function rather do it using another functional interface. For example:void doSomething(Supplier<Optional<String>> urlSupplier) {...
View ArticleAnswer by Eliezer Garza for Why should Java 8's Optional not be used in...
after a lot of debate at my new posting we came with this conventionfor public methods:a primitive means not null (obvious)an Object Backed by a primitive means it's nullableeven if it's not a...
View Article