oop - Scala can not resolve inherited Java interface constant members -


class hierarchy in java:

interface: cluster, classify

class kluster hierarchy show below

cluster  <- ,             +-- kluster classify <- ' 

file: oop/cluster.java

package oop;  public interface cluster {     public string hello = "hello"; } 

file: oop/kluster.java

package oop;  interface classify {     public string goodbye = "good bye"; }  public class kluster implements cluster, classify {  } 

file: oop/klustermain.java

package oop;  public class klustermain {     public static void main(string[] args) {         system.out.println(kluster.hello);         system.out.println(kluster.goodbye);     } } 

till works expected. can print hello , goodbye constants.

now when try access them scala compiler, gives error.

file: oop/cluster.scala

package oop  object cluster {   def main(args: array[string]) {     val k = new kluster     println(cluster.hello)     println(classify.goodbye)     println(kluster.hello) // <- problematic line   } } 

errors:

scala problem value hello not member of object oop.kluster /scala-snippets/src/main/scala/oop/cluster.scala line 8 

why can't scala resolve hierarchy kluster object implements both cluster , classify interfaces ?

you know putting constants interfaces use them in implementing classes bad approach, don't you? in java use final class private constructor , use import static shorten constant names, if needed. in scala use objects , imports. scala not have notion of static fields - has objects instead participate in inheritance properly. impossible unify static fields java proper object-oriented system, in scala can't use static members (fields , methods) subclasses.

see here.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -