How to access a Java static method from Scala given a type alias for that class it resides in

后端 未结 1 1256
孤独总比滥情好
孤独总比滥情好 2021-02-08 02:08

Given the type-alias type Cal = java.util.Calendar how can the static getInstance method be accessed? I tried the following in Scala REPL:

1条回答
  •  花落未央
    2021-02-08 03:02

    You can't.

    Yes, import java.util.{Calendar => Cal} is really your best bet.

    Conceptually, Scala object members are similar to static members of Java classes. This might suggest the following would work, but it doesn't since there are actually no singleton objects available for Java classes.

    scala> val Cal = java.util.Calendar
    :13: error: object Calendar is not a value
           val Cal = java.util.Calendar
                               ^
    

    0 讨论(0)
提交回复
热议问题