作业一:
package day03
class Student(var name:String,var id:Long) {
}
反编译之后的结果:
// Decompiled Using: FrontEnd Plus v2.03 and the JAD Engine
// Available From: http://www.reflections.ath.cx
// Decompiler options: packimports(3)
// Source File Name: Person.scala
package day03;
import scala.Int$;
import scala.Predef$;
import scala.collection.Seq;
import scala.collection.mutable.StringBuilder;
public class Person
{
public int study()
{
Predef$.MODULE$.print("\u6B63\u5728\u5B66\u4E60");
return 1;
}
public void study(String name, int age)
{
Predef$.MODULE$.print((new StringBuilder()).append(name).append("\u6B63\u5728\u5B66\u4E60").append(Int$.MODULE$).toString());
}
public void study(Seq x)
{
x.foreach(new Object() /* anonymous class not found */
class .anonfun.study._anm1 {}
);
}
public int add(int x, int y)
{
return x + y;
}
public void add(int a, int b)
{
int _tmp = a + b;
}
public Person()
{
}
}
可以在Scala中调用JavaBean的getter和setter方法,在定义属性前面加上注解 @BeanProperty 但是我们不应该这么做。
作业二:(不太准确)
package day03
//maker制造商 model型号 year年份 number车牌号
class Car(val maker:String="123",val model:String="234",val year:Int= -1,var number:String="0000") {
def this(maker: String,model:String,year:Int){
this(maker,model,year,"")
this.number=number
}
def this(number: Int){
this("","",-2,"")
}
def this(year:Int,number: String){
this("","",year,number)
}
override def toString: String = {
maker+model+year+number
}
}
object test4{
def main(args: Array[String]): Unit = {
val a = new Car() //程序入口还是主构造函数
println(a.year)
}
}