Reputation: 1706
I have Scala class that will generate an Option[StructType]
value which will be used in a Java function. In that java function, I need to check if this Option[StructType]
is Scala None
or not. How do I do that?
class Person(columns : String) {
val recordStruct : Option[StructType] = {
if ( columns != null && !columns.isEmpty()) {
Some(new StructType(fields.map(field =>
StructField(field, StringType, true)).toArray))
} else {
None
}
}
}
StructType structure = person.recordStruct().get();
// how to check if structure is None (in scala) ????
if (structure is None) {
// ...
}
Upvotes: 1
Views: 5571
Reputation: 37822
Option<StructType> maybeStructure = person.recordStruct();
if (maybeStructure.isEmpty()) {
// do something if None
} else {
StructType structure = person.recordStruct().get();
// now you can use structure...
}
Upvotes: 6