Constructor


$ cat a.scala 
import java.util._
class Cons1(
  var date: Date = new Date)

class Cons2 {
  var date: Date = new Date
}

$ scalac a.scala
  • Cons1.class
  • Cons1$.class
  • Cons2.class

$ javap -private Cons2
Compiled from "a.scala"
public class Cons2 extends java.lang.Object implements scala.ScalaObject{
    private java.util.Date date;
    public java.util.Date date();
    public void date_$eq(java.util.Date);
    public Cons2();
}



$ javap -private Cons1
Compiled from "a.scala"
public class Cons1 extends java.lang.Object implements scala.ScalaObject{
    private java.util.Date date;
    public static final java.util.Date init$default$1();
    public java.util.Date date();
    public void date_$eq(java.util.Date);
    public Cons1(java.util.Date);
}
$ javap -private Cons1$
Compiled from "a.scala"
public final class Cons1$ extends java.lang.Object implements scala.ScalaObject{
    public static final Cons1$ MODULE$;
    public static {};
    public java.util.Date init$default$1();
    private Cons1$();
}


scala> :load ./a.scala
Loading ./a.scala...
import java.util._
defined class Cons1
defined class Cons2

scala> val x = new Cons1
x: Cons1 = Cons1@7cb64078

scala> val y = new Cons2
y: Cons2 = Cons2@17698cbe

scala> x.date   
res2: java.util.Date = Fri Dec 24 10:32:11 CST 2010

scala> y.date  
res3: java.util.Date = Fri Dec 24 10:32:27 CST 2010

scala> x.

asInstanceOf   date           date_=         equals         getClass       hashCode       isInstanceOf   notify
notifyAll      toString       wait

scala> y. 

asInstanceOf   date           date_=         equals         getClass       hashCode       isInstanceOf   notify
notifyAll      toString       wait


Comments