Possible Duplicate:
Why Option[T] ?
i have a problem in my project
how do I retrieve data from the value: [some (test)] and only take the value of (test) only. and using the get method?
or
how do i change the form of value: [some (test)] to “test” just
Basically, don’t use get() ever. There’s no situation in which it is a better choice than the alternatives. Option is a way of indicating in the type system that a function might not return what you want. You might think of it as a collection containing 0 or 1 things.
Take a look at the API docs which show several different ways to handle Option; as a collection using map/flatMap, getOrElse, for comprehensions, and pattern matching.
e.g. map:
If maybeData is None, nothing happens. If it is Some() you will get back an Option containing the result of doSomethingWithAString(). Note that this will be Option[B] where B is the return type of doSomethingWithAString.
e.g. getOrElse:
If data is Some, result is “test”, otherwise it is “N/A”.
e.g. pattern matching:
You get the picture (note this assumes doSomethingWithAString returns String).
If you use get() and maybeData is None, you get the joy of handling the equivalent of nullpointers. Nobody wants that.