scala教程:主构造器和辅助构造器、反编译 作者:马育民 • 2021-12-07 11:31 • 阅读:10106 # 代码 ``` package stdobj object Std6_主构造器 { def main(args: Array[String]): Unit = { val cool = new Std6_phone("骁龙870",512) // println(cool.cpu) println(cool.rom) println(cool.screen) println(cool.ram) } } /** * 如果主构造器没有形参,那么就编译成无参构造方法 * * @param cpu * @param rom */ class Std6_phone (cpu:String,var rom:Int) { var screen:Double = _ var ram:Int = 128 def this() = { this("骁龙",128) } def this(length:Int,rom:Int) = { this("骁龙",rom) } def this(cpu:String,rom:Int,lenght:Int) = { this(cpu,rom) } } ``` ### 反编译 [![](https://www.malaoshi.top/upload/pic/scala/146D6EA5-1E32-4f74-B637-FE6CF52CF497.png)](https://www.malaoshi.top/upload/pic/scala/146D6EA5-1E32-4f74-B637-FE6CF52CF497.png) 原文出处:http://malaoshi.top/show_1IX2MXswrV3T.html