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
>
The first line is
private var f = 0;
Here the identifier 'f' is seen first and the 'var' means the
type is not known.
However, the =0 causes the "type inference" machinery to kick
and specify the 'type' for f as 'Int'.
With this 'f' is declared and defined.
The next line is again an attempt to define 'f'.
Hence the error.
thanks
Saifi.