//scala Object Test{ def main(args:Array[String]):Unit = { println("hello") } }
//java模拟代码【通过jd-gui解析】 public class Test{ public static void main(String[] paramArrayOfString){ Test$.MODULE$.main(paramArrayOfString); } } final class Test${ public static final Test$ MODULE$; static{ MODULE$ = new Test$(); } public void main(String[] args){ System.out.println("hello"); } }
可以理解为,scala在运行时做了一个包装,把静态和非静态分为两个部分。
- object Test对应的是一个Test$的一个静态对象MODULE$
- 在我们的程序中,MODULE$是一个单例对象