如何在Java代码中检查scala选项类型是否为None

如何在Java代码中检查scala选项类型是否为None,java,scala,Java,Scala,我有一个Scala类,它将生成一个选项[StructType]值,该值将在Java函数中使用。在该java函数中,我需要检查这个选项[StructType]是否为ScalaNone。我该怎么做 Scala类: Java函数: 选项maybeststructure=person.recordStruct(); if(maybesttructure.isEmpty()){ //如果没有,就做点什么 }否则{ StructType结构=person.recordStruct().get(); //现在

我有一个Scala类,它将生成一个
选项[StructType]
值,该值将在Java函数中使用。在该java函数中,我需要检查这个
选项[StructType]
是否为Scala
None
。我该怎么做

Scala类: Java函数: 选项maybeststructure=person.recordStruct(); if(maybesttructure.isEmpty()){ //如果没有,就做点什么 }否则{ StructType结构=person.recordStruct().get(); //现在您可以使用结构。。。 }
选项maybeststructure=person.recordStruct();
if(maybesttructure.isEmpty()){
//如果没有,就做点什么
}否则{
StructType结构=person.recordStruct().get();
//现在您可以使用结构。。。
}

如果(!structure.isDefined())
将告诉您
结构是否为
无。除了
结构
不是真正的
选项
person.recordStruct()
是。我看不出structType有isDefined()函数。这是因为
structType
不是
选项(它是
structType
,duh)。请参阅我上面更新的评论。如果愿意,您可以执行
StructType structure=person.recordStruct().orNull()
,因此我应该使用person.recordStruct().isDefined(),而不是structure.isDefined()?
if(!structure.isDefined())
将告诉您
structure
是否为
None
。除了
结构
不是真正的
选项
person.recordStruct()
是。我看不出structType有isDefined()函数。这是因为
structType
不是
选项(它是
structType
,duh)。请参阅我上面更新的评论。如果愿意,您可以执行
StructType structure=person.recordStruct().orNull()
,因此我应该使用person.recordStruct().isDefined(),而不是structure.isDefined()?谢谢。通过查看它们,我似乎可以在选项类型上使用isDefined()或isEmpty()。正确-当然
o.isDefined()!o、 isEmpty()
。谢谢。通过查看它们,我似乎可以在选项类型上使用isDefined()或isEmpty()。正确-当然
o.isDefined()!o、 isEmpty()
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) {
    // ...
}
Option<StructType> maybeStructure = person.recordStruct();
if (maybeStructure.isEmpty()) { 
    // do something if None
} else {
    StructType structure =  person.recordStruct().get();
    // now you can use structure...
}