The Artima Developer Community
Sponsored Link

Programming in Scala Forum
17.4 '+='

1 reply on 1 page. Most recent reply: Nov 20, 2008 10:20 AM by Martin Weber

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Martin Weber

Posts: 7
Nickname: ephaeton
Registered: Sep, 2008

17.4 '+=' Posted: Nov 20, 2008 10:18 AM
Reply to this message Reply
Advertisement
Now is this a scala error or a book error..

"The same idea" [to interpret x method= y as x = x method y] "applies to any method ending in =, not just the += method."



class X(val x: Int) {
def freak(other: X) = new X(x+other.x)
def +(other: X) = new X(x+other.x)
}

var x = new X(1)
x += new X(2)
x.x => 3
x freak= new X(3)
error: reassignment to val
x freak= new X(3)
^
on the 2.7.2 final which is the supposed companion for the book?


Martin Weber

Posts: 7
Nickname: ephaeton
Registered: Sep, 2008

Re: 17.4 '+=' Posted: Nov 20, 2008 10:20 AM
Reply to this message Reply
Just to follow up, at the end of the section it says "... but it is more general because every operator ending in = can be converted." (so prolly a book error)

Flat View: This topic has 1 reply on 1 page
Topic: Listing 20.4 and surrounding.. Previous Topic   Next Topic Topic: book release date

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use