Scala can not resolve inherited Java interface constant members

前端 未结 1 1002
情话喂你
情话喂你 2021-01-19 06:26

Class hierarchy in Java:

Interface: Cluster, Classify

Class Kluster hierarchy is show below

Cluster  <- ,
              


        
相关标签:
1条回答
  • 2021-01-19 07:18

    You do know that putting constants into interfaces to use them in implementing classes is bad approach, don't you? In Java you use final class with private constructor and use import static to shorten constant names, if needed. In Scala you use objects and imports. But Scala does not have notion of static fields - it has objects instead which participate in inheritance properly. It was impossible to unify static fields from Java with proper object-oriented system, so in Scala you can't use static members (fields and methods) from subclasses.

    See also here.

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