开发者

In Scala, why does getInstance fail to work with GregorianCalendar?

开发者 https://www.devze.com 2023-04-09 09:19 出处:网络
java.util.GregorianCalendar.getInstance(); Works in Java java.util.Calendar.getInstance(); Works in Scala
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)

0

精彩评论

暂无评论...
验证码 换一张
取 消