scala - Why is there an Option.get method -
why method get
defined in option
, not in some
?
one apply pattern matching or use foreach
, map
, flatmap
, getorelse
preferred anyway without danger of runtime exceptions if none.get
called.
are there cases get
method convinent justifies this? using get
method reminds me java "i don't have check null because know var set" , see nullpointerexception
.
option.get useful when know, reasoning isn't captured type system, value have not none. however, should reach when you've tried:
- arranging knowledge expressed types.
- using option processing methods mentioned (flatmap, getorelse etc), , none of them fit elegantly.
it's convenient throwaway / interactive code (repl, worksheets etc).
Comments
Post a Comment