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?
Scala class:
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
}
}
}
Java function:
StructType structure = person.recordStruct().get();
// how to check if structure is None (in scala) ????
if (structure is None) {
// ...
}
if(!structure.isDefined())would tell you ifstructureisNone. Except thatstructureisn't really anOption.person.recordStruct()is.structTypeisn't anOption(it's aStructType, duh). See my updated comment above.StructType structure = person.recordStruct().orNull()if you prefer