> 
> On Wed, 10 Jun 2009, Rajkumar Goel wrote:
> 
> > Hi all,
> > This is what the error I got when I wrote the following code in SCALA.
> > scala> class Wont{
> >      | private var f=0;
> >      | def f=1;
> >      | }
> > <console>:6: error: method f is defined twice
> >        def f=1;
> > ie., it is treating a feild also a method.
> > Any pointers ???Why such behavior.
> > Thanks,
> > RajkumarGoel
> > 

Dear RKG:

The answer to 'WHY' is usually one-layer deep :-)

ie. we need to compile each of the individual cases in a .scala
file and then create the disassembly.

Please see the output below.

Case I
-----------

class Wont{
    private var f=0
    //def f=1
}

sa...@speed /data/workarea/hacking/scala $ javap -private -s Wont
Compiled from "Wont.scala"
public class Wont extends java.lang.Object implements scala.ScalaObject{
private int f;
  Signature: I
public Wont();
  Signature: ()V
private void f_$eq(int);
  Signature: (I)V
private int f();
  Signature: ()I
}


--
Case II
-----------

class Wont{
    //private var f=0
    def f=1
}

sa...@speed /data/workarea/hacking/scala $ javap -private -s Wont
Compiled from "Wont.scala"
public class Wont extends java.lang.Object implements scala.ScalaObject{
public Wont();
  Signature: ()V
public int f();
  Signature: ()I
}

Can you see the common method 'int f()' across both ?


thanks
Saifi.

Reply via email to