Reputation: 913
This is probably a very silly question, but I have a case class which takes as a parameter Option[Timestamp]. The reason this is necessary is because sometimes the timestamp isn't included. However, for testing purposes I'm making an object where I pass in
Timestamp.valueOf("2016-01-27 22:27:32.596150")
But, it seems I can't do this as this is an actual Timestamp, and it's expecting an Option.
How do I convert to Option[Timestamp] from Timestamp. Further, why does this cause a problem to begin with? Isn't the whole benefit of Option that it could be there or not?
Thanks in advance,
Upvotes: 1
Views: 590
Reputation: 144136
Option indicates the possibility of a missing value, but you still need to construct an Option[Timestamp]
value. There are two subtypes for Option - None
when there is no value, and Some[T]
which contains a value of type T
.
You can create one directly using Some
:
Some(Timestamp.valueOf("2016-01-27 22:27:32.596150"))
or Option.apply
:
Option(Timestamp.valueOf("2016-01-27 22:27:32.596150"))
Upvotes: 4