In Scala, why does getInstance fail to work with GregorianCalendar?
java.util.GregorianCalendar.getInstance();
Works in Java
java.util.Calendar.getInstance();
Works in Scala
java.util开发者_运维知识库.GregorianCalendar.getInstance();
Fails in Scala. getInstance is not a member of object java.util.GregorianCalendar
There are no static in scala, rather there are in singleton objects and methods in them, and so they are not considered inherited, even when defined in java. getInstance
is defined on Calendar
. In java, calling it on GregorianCalendar
does call the exact same method as calling it on Calendar
. In scala, you have to call it on Calendar
. (BTW, calling it on GregorianCalendar in java is rather misleading)
精彩评论