1

I have a Option<Object> from which i am trying to get long value. But this does not work. I tried the below steps but could not get the value as it shows compiler error. Please help.

//#1
Option<Object> expireTimestamp = offsetAndMetadata.expireTimestamp();
expireTimestamp.getOrElse(0L);

Also tried

Option<Object> expireTimestamp = offsetAndMetadata.expireTimestamp();
expireTimestamp.getOrElse(new Long(0));


//#2
Option<Long> expireTimestamp = (Option<Long>) offsetAndMetadata.expireTimestamp();

The method getOrElse(Function0) in the type Option is not applicable for the arguments (long)

wandermonk
  • 6,856
  • 6
  • 43
  • 93
  • I think @JoopEggen is on the money. `getOrElse` takes a lazy value, i.e. a Producer function with no parameters, not the value directly. – Thilo May 16 '19 at 11:00
  • Maybe you should use the Java converter library to change it to a Java Optional first and take it from there: https://stackoverflow.com/q/38325656/14955 – Thilo May 16 '19 at 11:02

1 Answers1

2

As, commented by Thilo, I tried the below code and it worked

offsetAndMetadata.expireTimestamp().getOrElse(() -> 0L)
wandermonk
  • 6,856
  • 6
  • 43
  • 93