Javaはエラーになりますから、Scalaの「Val関数」を呼び出します

REMISハルーン:

次のように私は、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のヴァル機能を呼び出すJavaコード:

Long minTimestampOfGranularity = getTimestampEpochMillis(year, 1, 1, 0, 0, 0, 0);
マリオGalic:

試します

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()リターンをscala.Function7、私たちは最初にコールする必要がgetTimestampEpochMillis()私たちすることができます前に、apply引数を指定します。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=231981&siteId=1