Static inner classes in scala

前端 未结 5 1438
旧时难觅i
旧时难觅i 2020-12-28 14:03

What is the analog in Scala of doing this in Java:

public class Outer {
  private Inner inner;

  public static class Inner {
  }

  public Inner getInner()          


        
5条回答
  •  天命终不由人
    2020-12-28 14:30

    In scala if you need to create a some static methods you can use a companion object, with the same name of the class, where you store all the pseudo static methods. Ex:

    class A {
    }
    
    object A {
        def xpto // define some pseudo static methods here..
    }
    

    Then you can just use A.xpto.
    Try to read more about companion modules on scala

提交回复
热议问题