称之为Scala“;“val函数”;来自Java的错误

称之为Scala“;“val函数”;来自Java的错误,java,scala,scala-java-interop,Java,Scala,Scala Java Interop,我有一个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){

我有一个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);
试一试

请注意
gettimestampepepochmillis()
中的括号
()
。使用我们得到的

public scala.Function7 getTimestampEpochMillis();

我们看到的
getTimestampEpochMillis()
返回
scala.Function7
,因此我们首先必须调用
getTimestampEpochMillis()
,然后才能
应用这些参数。

getTimestampEpochMillis.apply(…)
谢谢。。你能把它作为解释如何、为什么等的答案吗?Java不使用sugar函数语法,将
(…)
映射到
apply
,因为Scala中的函数是类
Function1
Function2
的实例。。。这些类有一个
apply
方法,每当您在Scala中调用这些函数时,就会调用该方法。但是,您必须使用Java显式地调用这些
apply
方法。
getTimestampEpochMillis().apply(year, 1, 1, 0, 0, 0, 0);
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();