From Scala, access static inner class of Java class

我们两清 提交于 2021-02-08 11:57:28

问题


I have a Java class which I'm working with in Scala. I can instantiate the class, but I don't see how to instantiate a public static class within the outer class from Scala. Can anyone point me to the answer?

(I've read lots of posts that say how to use "static" members in Scala code. That is not what I'm looking for.)


回答1:


In my case something like that works:

  • Java class

    package test.java;
    
    public class Test {
      public static class TestInner {}
    }
    
  • Scala class

    package test.scala
    
    import test.java.Test
    
    object Main {
    
      def main(args: Array[String]): Unit = {
        new Test.TestInner()
      }
    }
    


来源:https://stackoverflow.com/questions/42322033/from-scala-access-static-inner-class-of-java-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!