Optional by Stuart Marks

  Рет қаралды 30,838

Devoxx

Devoxx

Күн бұрын

Пікірлер: 27
@wangjie8003
@wangjie8003 4 жыл бұрын
Best walk-through material that I could find in the internet!
@MereAYT
@MereAYT 4 жыл бұрын
Very informative and well-presented. Thanks!
@souvikadhikary8990
@souvikadhikary8990 3 жыл бұрын
So at the end , to summarise, If you are obsessed with functional programming & lambdas, go for optional, or else we should use the traditional way of coding style.
@bizoitz86
@bizoitz86 7 жыл бұрын
Optional.get -> no arg Optional.orElseThrow
@osematouati2430
@osematouati2430 2 жыл бұрын
I question for the geeks: in 28:00, I can't see the benefit of the second map (.map(Optional::of)) why is it included? in which use case is it significant.
@tanveerhasan2382
@tanveerhasan2382 2 жыл бұрын
Because we want the return value to be an optional as well. Without the 2nd map, orElse would return a BigDecimal since we are dealing with Optional. But the 2nd map turns that into Optional so when we call orElse we end up with Optional which is what we want
@anuradharanasinghe9512
@anuradharanasinghe9512 2 жыл бұрын
Very informative. Thank you
@feddeschaeffer7116
@feddeschaeffer7116 6 жыл бұрын
I feel like the object-oriented way to implement a ‘field that may not need to be stored in all objects that fulfill this interface’ would be defining a separate class of objects that don't store it, and implementing the interface with a method that returns whatever it needs to return there, such as Optional.empty().
@feddeschaeffer7116
@feddeschaeffer7116 6 жыл бұрын
Would writing it that way feel out of place in Java?
@feddeschaeffer7116
@feddeschaeffer7116 2 жыл бұрын
For completeness, this question was a response to the scenario sketched at 30:45. I now understand that the speaker probably meant exactly the pattern I was thinking of with the term ‘null object pattern’: one class that has methods that do things using the value of the field and another class that implements those methods to do whatever is right when the field is not applicable.
@DeepakPandey-ij3bz
@DeepakPandey-ij3bz 5 жыл бұрын
As per rule 6 we should not use optional in collection. Then if fetch data from database and get value as null in a collection reference to the method. Then we should not use optional right. Then again we have to use null check. What is the point of creating optional then? Any suggestions on this.
@tanveerhasan2382
@tanveerhasan2382 2 жыл бұрын
Use optional as return value for methods, as mentioned in 35:45
@grsalvi
@grsalvi 6 жыл бұрын
So many places not use were mentioned but where to use optional then ?
@sobanya_228
@sobanya_228 6 жыл бұрын
He says, you should never return null. Make return types typesafe with Optional
@AlanDarkworld
@AlanDarkworld 7 жыл бұрын
A lot of the pain of having to deal with Optionals would be eliminated entirely if only javac was capable of performing proper NULL analysis. Or take a page from functional languages: String? myvar; //
@spirridd
@spirridd 7 жыл бұрын
You're talking about safe navigation operator.
@spirridd
@spirridd 7 жыл бұрын
By the way you can use annotations like @Nullable and @NonNull.
@jonathancamarena3117
@jonathancamarena3117 2 жыл бұрын
i guess this is why rust uses unrwap() instead of get()
@sobanya_228
@sobanya_228 6 жыл бұрын
Where Optional violates monad laws?
@bernardobuffa2391
@bernardobuffa2391 7 жыл бұрын
just horrible stuff.. will never use this monstruosity... Long live the null
@Omega3131
@Omega3131 7 жыл бұрын
It's extremely useful in some cases.
@AndreaTortorella
@AndreaTortorella 7 жыл бұрын
Most modern languages have this concept
@pockpicket9360
@pockpicket9360 3 жыл бұрын
it's probably one of the most usefull java feature
@bernardobuffa2391
@bernardobuffa2391 3 жыл бұрын
@@pockpicket9360 I think it just syntax sugar.. orElse... orElseThrow etc.. you can just replace all that with the old null testing... if(x==null) throw new MyException() if (x==null) x="default" etc. Am I missing something?
@Naglfar83
@Naglfar83 3 жыл бұрын
@@bernardobuffa2391 Yes, you are. Thing is, I don't want to check for null all the time. It's something that shouldn't be necessary. With Optionals I can respond to null values in a much more elegant way by just adding .orElse, .orElseGet or .orElseThrow. Checking for null is clunky, ugly and really old-fashioned.
Collections Refueled by Stuart Marks
51:42
Devoxx
Рет қаралды 15 М.
Thinking In Parallel by Stuart Marks and Brian Goetz
1:00:04
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26
отомстил?
00:56
История одного вокалиста
Рет қаралды 6 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 118 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 15 МЛН
Optionals In Java - Simple Tutorial
15:53
Coding with John
Рет қаралды 211 М.
Effective Unit Testing by Eliotte Rusty Harold
48:10
Devoxx
Рет қаралды 103 М.
Optional - The Mother of All Bikesheds by Stuart Marks
58:43
Java Streams: Beyond The Basics
49:21
Jfokus
Рет қаралды 72 М.
Collections Corner Cases by Stuart Marks
50:46
Devoxx
Рет қаралды 9 М.
Java 21… and Beyond
48:30
Java
Рет қаралды 24 М.
Java 8 Streams | Optional Usage and Best Practices | JavaTechie
22:22
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26