我有一個(gè) scala val 函數(shù),如下所示: 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() }當(dāng)我從 Java 調(diào)用此函數(shù)時(shí),出現(xiàn)以下錯(cuò)誤:[ERROR] required: no arguments [ERROR] found: int,int,int,int,int,int,int [ERROR] reason: actual and formal argument lists differ in length 調(diào)用 scala val 函數(shù)的 Java 代碼:Long minTimestampOfGranularity = getTimestampEpochMillis(year, 1, 1, 0, 0, 0, 0);
1 回答

叮當(dāng)貓咪
TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
嘗試
getTimestampEpochMillis().apply(year, 1, 1, 0, 0, 0, 0);
()
并注意中的括號(hào)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
,所以我們首先必須先調(diào)用,getTimestampEpochMillis()
然后才能調(diào)用apply
參數(shù)。
添加回答
舉報(bào)
0/150
提交
取消