- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
var constructor parameters
Tue, 2010-05-18, 18:26
Over at http://scala-forum.org/read.php?4,1399 this example came up:
class A(var x:Int) {
println("x=" + x)
x=99
println("x is now equal to " + x)
}
val test = new A(10)
resulting in:
x=10
x is now equal to 10
Not what the poster expected, and not what I expected. Can this be
according to spec somehow, or is it just a bug?
The behavior is the same in both 2.7 and 2.8.
Tue, 2010-05-18, 20:27
#2
Re: var constructor parameters
On Tue, May 18, 2010 at 12:47:45PM -0500, Colin Bullock wrote:
> It looks to be a bug (to me).
If that's not a bug I will eat my hat.
Tue, 2010-05-18, 21:07
#3
Re: var constructor parameters
On 18 May 2010 20:22, Paul Phillips <paulp@improving.org> wrote:
On Tue, May 18, 2010 at 12:47:45PM -0500, Colin Bullock wrote:
> It looks to be a bug (to me).
If that's not a bug I will eat my hat.
I bet it's a stetson too! There's some good eating in those...
--
Paul Phillips | Simplicity and elegance are unpopular because
Everyman | they require hard work and discipline to achieve
Empiricist | and education to be appreciated.
i pull his palp! | -- Dijkstra
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
Tue, 2010-05-18, 21:07
#4
Re: var constructor parameters
On Tue, May 18, 2010 at 12:50 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On 18 May 2010 20:22, Paul Phillips <paulp@improving.org> wrote:On Tue, May 18, 2010 at 12:47:45PM -0500, Colin Bullock wrote:
> It looks to be a bug (to me).
If that's not a bug I will eat my hat.
I bet it's a stetson too! There's some good eating in those...
I wonder if this is Paul's secret life: http://www.hatworksbypaul.com/
--
Paul Phillips | Simplicity and elegance are unpopular because
Everyman | they require hard work and discipline to achieve
Empiricist | and education to be appreciated.
i pull his palp! | -- Dijkstra
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
Tue, 2010-05-18, 21:27
#5
Re: var constructor parameters
On 18 May 2010 21:05, David Pollak <feeder.of.the.bears@gmail.com> wrote:
On Tue, May 18, 2010 at 12:50 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On 18 May 2010 20:22, Paul Phillips <paulp@improving.org> wrote:On Tue, May 18, 2010 at 12:47:45PM -0500, Colin Bullock wrote:
> It looks to be a bug (to me).
If that's not a bug I will eat my hat.
I bet it's a stetson too! There's some good eating in those...
I wonder if this is Paul's secret life: http://www.hatworksbypaul.com/
How long did you spend searching for that? :P
--
Paul Phillips | Simplicity and elegance are unpopular because
Everyman | they require hard work and discipline to achieve
Empiricist | and education to be appreciated.
i pull his palp! | -- Dijkstra
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
Tue, 2010-05-18, 21:37
#6
Re: var constructor parameters
On Tue, May 18, 2010 at 1:25 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On 18 May 2010 21:05, David Pollak <feeder.of.the.bears@gmail.com> wrote:
On Tue, May 18, 2010 at 12:50 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On 18 May 2010 20:22, Paul Phillips <paulp@improving.org> wrote:On Tue, May 18, 2010 at 12:47:45PM -0500, Colin Bullock wrote:
> It looks to be a bug (to me).
If that's not a bug I will eat my hat.
I bet it's a stetson too! There's some good eating in those...
I wonder if this is Paul's secret life: http://www.hatworksbypaul.com/
How long did you spend searching for that? :P
It's 2 blocks from my house. ;-)
--
Paul Phillips | Simplicity and elegance are unpopular because
Everyman | they require hard work and discipline to achieve
Empiricist | and education to be appreciated.
i pull his palp! | -- Dijkstra
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
--
Kevin Wright
mail/google talk: kev.lee.wright@googlemail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
public A(int x)
{
this.x = x;
super();
Predef$.MODULE$.println(BoxesRunTime.boxToInteger(x));
x_$eq(99);
Predef$.MODULE$.println(BoxesRunTime.boxToInteger(x)); // Field shadowed by param
}
- Colin