当前我有一个名为example的抽象类,三个扩展抽象类的case类和一个返回类型为example的函数。在函数中,当满足某个条件时,它应该返回一个示例类型,但由于某种原因它说:类型不匹配,找到:单元,要求:示例Scala在if/else语句中返回对象类型
我不明白为什么,因为我在主函数在每个if语句的结束返回例如型...
abstract class example
case class type1() extends example
case class type2() extends example
case class type3() extends example
def func(): example = {
if (condition)
return (val x= type1())
else if (condition)
return (val x= type2())
else if (condition)
return (val x= type3())
}
,我打电话FUNC()
注意:在Scala中不使用'return',通常[完全不使用](https://tpolecat.github.io/2014/05/09/return.html)。 Scala中的'return'与Java中的不一样! –