亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 Java 調用 Scala“val 函數”會出錯

從 Java 調用 Scala“val 函數”會出錯

牛魔王的故事 2023-03-23 15:08:15
我有一個 scala val 函數,如下所示:  val getTimestampEpochMillis = (year:Int, month:Int, day:Int, hour:Int, quarterHour:Int, minute:Int, seconds:Int) => {    var tMinutes = minute    var tSeconds = seconds    if(minute == 0){      if(quarterHour == 1){        tMinutes = 22        tSeconds = 30      }else if(quarterHour == 2){        tMinutes = 37        tSeconds = 30      }else if(quarterHour == 3){        tMinutes = 52        tSeconds = 30      }else if(quarterHour == 0){        tMinutes = 7        tSeconds = 30      }    }    val localDateTime = LocalDateTime.of(year, month, day, hour, tMinutes, tSeconds)    localDateTime.atZone(ZoneId.of("GMT")).toInstant().toEpochMilli()  }當我從 Java 調用此函數時,出現以下錯誤:[ERROR]   required: no arguments                                          [ERROR]   found: int,int,int,int,int,int,int                              [ERROR]   reason: actual and formal argument lists differ in length    調用 scala val 函數的 Java 代碼:Long minTimestampOfGranularity = getTimestampEpochMillis(year, 1, 1, 0, 0, 0, 0);
查看完整描述

1 回答

?
叮當貓咪

TA貢獻1776條經驗 獲得超12個贊

嘗試

getTimestampEpochMillis().apply(year, 1, 1, 0, 0, 0, 0);

()并注意中的括號getTimestampEpochMillis()。javap使用我們得到的檢查生成的類

public scala.Function7<java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, scala.runtime.BoxedUnit> getTimestampEpochMillis();

我們看到getTimestampEpochMillis()returns 的地方scala.Function7,所以我們首先必須先調用,getTimestampEpochMillis()然后才能調用apply參數。


查看完整回答
反對 回復 2023-03-23
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號