本文介绍了从Scala,访问Java类的静态内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Scala 中使用的 Java 类.我可以实例化该类,但我看不到如何在 Scala 的外部类中实例化 public static 类.谁能指出我的答案?

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?

(我读过很多关于如何在 Scala 代码中使用静态"成员的帖子.这不是我想要的.)

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

推荐答案

在我的情况下,类似的东西是有效的:

In my case something like that works:

  • Java 类

  • Java class

package test.java;

public class Test {
  public static class TestInner {}
}

  • Scala 类

  • Scala class

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

  • 这篇关于从Scala,访问Java类的静态内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-18 11:31