Skip to content

scala object don't support inheritance but in scala reference java class parent class static methods and static variable not available #11230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Le-Dai opened this issue Oct 30, 2018 · 4 comments

Comments

@Le-Dai
Copy link

Le-Dai commented Oct 30, 2018

object AccumuloTest {
  def main(args: Array[String]): Unit = {
    //无法引用 父类静态方法
    Tjava.sayHello()
    Tjava.TJavaSayHello()

    //无法引用继承的静态变量
    val v = Tjava.v1
    val v1 = new Tjava
    Test1.MysayHello()
    //无法引用 父类静态方法
    Test1.sayHello()
  }

}

public class Father {
    public static String v1 = "haha";
    public static void sayHello() {
        System.out.println("hello");
    }
}

object Test1 extends Test2{
  def MysayHello(): Unit = {
    System.out.println("hello")
  }
}

public class Test2 {
    public static void sayHello(){
        System.out.println("hello");
    }
}

//object 不支持 继承object
object Test3 extends Test4{
  def MysayHello(): Unit = {
    System.out.println("hello")
  }
}

object Test4 {
  def sayHello(): Unit = {
    System.out.println("hello")
  }
}


public class Tjava extends Father{
    public static void TJavaSayHello(){
        System.out.println("tjava hello");
    }
    public static void main(String[] args) {
        Tjava.sayHello();
        Tjava.TJavaSayHello();

    }
}

problem.txt

@Jasper-M
Copy link

Possibly a duplicate of #11226?

@SethTisue
Copy link
Member

SethTisue commented Oct 30, 2018

which is itself a duplicate of #9272. I've commented on 9272 with my own current take on this. let's continue any further discussion there.

@HiIcy
Copy link

HiIcy commented Jul 1, 2020

@MrDLontheway 请问现在有好的解决方案吗,我最近也遇到这个问题/(ㄒoㄒ)/~~

@SethTisue
Copy link
Member

SethTisue commented Jul 1, 2020

@hilcy please use #9272

@scala scala locked as resolved and limited conversation to collaborators Jul 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants