函数重载的方法值在scala中用可选错误应用

j13ufse2  于 2021-05-29  发布在  Spark
关注(0)|答案(1)|浏览(493)

我有以下代码作为粘合工作的一部分:

def forTxnType(dynamicRecord: DynamicRecord): DynamicRecord = {
val s = dynamicRecord.getField("transactiondirection")
val s_out = dynamicRecord.getField("transfermechanism")
val s_in = dynamicRecord.getField("terminalid").mkString("")
val m_Wire = List("FWWRD", "WTPCT", "WTROL")
val m_ACH = List("9CACH","9DACH","WTB19","WTB20","WTCN0","WTCN9","WTFP0","WTLEG","WTM20","WTP20","WTPMD","WTSNR","WTSPN","WTT20","WTTEF") 
val m_ACAT = List("NSTFR","TSTFR","NSADJ") 
val m_Check = List("MGRCF","WTFEE","WTFP0","WTLEG","WTM20","WTP20","WTROL","WTSPN","WTTEF","Z9CHK") 
val m_CashJournal = List("AUDEP","AUFEE","CSCSG","WTB20","WTBYP","WTCN0","WTCN9")

val etype = if(s.equals("Outgoing")){
    s_out
} else {
if(m_Check.contains(s_in)){
        "Check"
    }
    else if(m_CashJournal.contains(s_in)){
        "Cash_journal"
    }
    else if(m_Wire.contains(s_in)){
        "Wire"
    }
    else if(m_ACH.contains(s_in)){
        "ACH"
    }
    else if(m_ACAT.contains(s_in)){
        "ACAT"
    }
    else{
        "NoType"
    }
   }

dynamicRecord.addField("transactionType", StringNode(etype))
dynamicRecord
}

它在-dynamicrecord.addfield(“transactiontype”,stringnode(etype))行上给出了以下错误:
重载方法值应用于替换项

7nbnzgx9

7nbnzgx91#

返回类型 def getField( path : String ) : Option[Any]
Option StringNode 将只接受类型为的数据 String 但是你的 etype 数据类型为类型 Any ,因此您将得到错误 overloaded method value apply with alternatives 要解决此问题,请更改 s_outs_out.get 在你的if街区。
检查以下代码。

val etype = if(s.equals("Outgoing")){
    s_out.get // Add .get here
} else {...}

相关问题