<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Scala for Java Refugees Part 2: Basic OOP</title>
	<atom:link href="http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:01:44 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Design Pattern</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4933</link>
		<dc:creator>Design Pattern</dc:creator>
		<pubDate>Mon, 08 Feb 2010 15:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4933</guid>
		<description>Hello Paul,

If you want to overload teh accessors, you need to rename the property:

[code]
class Person(private var theAge:Int){

  def age = theAge

  def age_=(age:Int) = {
    if(age &gt; 120){
      throw new IllegalArgumentException(&quot;Person.age=&quot; + age + &quot;: Too old&quot;)
    } else {
      theAge=age
    }
  }

}
[/code]</description>
		<content:encoded><![CDATA[<p>Hello Paul,</p>
<p>If you want to overload teh accessors, you need to rename the property:</p>
<p>[code]<br />
class Person(private var theAge:Int){</p>
<p>  def age = theAge</p>
<p>  def age_=(age:Int) = {<br />
    if(age &gt; 120){<br />
      throw new IllegalArgumentException("Person.age=" + age + ": Too old")<br />
    } else {<br />
      theAge=age<br />
    }<br />
  }</p>
<p>}<br />
[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4929</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sun, 31 Jan 2010 23:12:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4929</guid>
		<description>Hi Daniel,

Firstly, thanks for this series of articles, I&#039;m working my way through them now.  Very helpful.

I was trying a few things out based on the examples here and the following will not compile and I would think that it should...  why am i unable to overload the function/variable defined in the &#039;constructor&#039;?

Code:

  class Person(var age:Int){

    def age_=(age:Int) = {
      if(age &gt; 120){
        throw new IllegalArgumentException(&quot;Too old&quot;)
      }
    }
  }

    val person = new Person(1)
    println(person.age)
    person.age = 50
    println(person.age)

Results in:

[ERROR]com/bob/HelloWorld.scala:18: error: ambiguous reference to overloaded definition,
both method age_= in class Person of type (Int)Unit
and  method age_= in class Person of type (Int)Unit
match argument types (Int)
    person.age = 50</description>
		<content:encoded><![CDATA[<p>Hi Daniel,</p>
<p>Firstly, thanks for this series of articles, I&#8217;m working my way through them now.  Very helpful.</p>
<p>I was trying a few things out based on the examples here and the following will not compile and I would think that it should&#8230;  why am i unable to overload the function/variable defined in the &#8216;constructor&#8217;?</p>
<p>Code:</p>
<p>  class Person(var age:Int){</p>
<p>    def age_=(age:Int) = {<br />
      if(age &gt; 120){<br />
        throw new IllegalArgumentException(&#8220;Too old&#8221;)<br />
      }<br />
    }<br />
  }</p>
<p>    val person = new Person(1)<br />
    println(person.age)<br />
    person.age = 50<br />
    println(person.age)</p>
<p>Results in:</p>
<p>[ERROR]com/bob/HelloWorld.scala:18: error: ambiguous reference to overloaded definition,<br />
both method age_= in class Person of type (Int)Unit<br />
and  method age_= in class Person of type (Int)Unit<br />
match argument types (Int)<br />
    person.age = 50</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rbsomeg</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4896</link>
		<dc:creator>rbsomeg</dc:creator>
		<pubDate>Fri, 25 Sep 2009 11:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4896</guid>
		<description>Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.6.0_13) on windows vista</description>
		<content:encoded><![CDATA[<p>Scala version 2.7.5.final (Java HotSpot(TM) Client VM, Java 1.6.0_13) on windows vista</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nibble</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4895</link>
		<dc:creator>Nibble</dc:creator>
		<pubDate>Thu, 24 Sep 2009 14:02:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4895</guid>
		<description>What version of Scala are you using?</description>
		<content:encoded><![CDATA[<p>What version of Scala are you using?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rbsomeg</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4894</link>
		<dc:creator>rbsomeg</dc:creator>
		<pubDate>Thu, 24 Sep 2009 08:59:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4894</guid>
		<description>Hi,

I am new to scala.

while compiling - the compiler just hangs and java processes keeps growing. Any idea what&#039;s going on?



C:\work\scala&gt;scala -d bin src/com/codecommit/examples/*.scala
2009-09-24 14:19:10
Full thread dump Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing):

&quot;Low Memory Detector&quot; daemon prio=6 tid=0x0225d400 nid=0x10d4 runnable [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

&quot;CompilerThread0&quot; daemon prio=10 tid=0x0225a400 nid=0xf7c waiting on condition [0x00000000..0x0444fa10]
   java.lang.Thread.State: RUNNABLE

&quot;Attach Listener&quot; daemon prio=10 tid=0x02259800 nid=0x8a4 runnable [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

&quot;Signal Dispatcher&quot; daemon prio=10 tid=0x0224ec00 nid=0x31c waiting on condition [0x00000000..0x00000000]
   java.lang.Thread.State: RUNNABLE

&quot;Finalizer&quot; daemon prio=8 tid=0x02246000 nid=0x1050 in Object.wait() [0x0435f000..0x0435fa68]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on  (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
        - locked  (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

&quot;Reference Handler&quot; daemon prio=10 tid=0x02244c00 nid=0xf9c in Object.wait() [0x00ddf000..0x00ddfae8]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on  (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:485)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
        - locked  (a java.lang.ref.Reference$Lock)

&quot;main&quot; prio=6 tid=0x000ea000 nid=0x1234 runnable [0x0039f000..0x0039fe28]
   java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        - locked  (a java.net.SocksSocketImpl)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.(Socket.java:366)
        at java.net.Socket.(Socket.java:209)
        at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:210)
        at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:224)
        at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:227)
        at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:232)
        at scala.tools.nsc.ScriptRunner$.compileWithDaemon(ScriptRunner.scala:237)
        at scala.tools.nsc.ScriptRunner$.compile$1(ScriptRunner.scala:315)
        at scala.tools.nsc.ScriptRunner$.withCompiledScript(ScriptRunner.scala:350)
        at scala.tools.nsc.ScriptRunner$.runScript(ScriptRunner.scala:413)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:168)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

&quot;VM Thread&quot; prio=10 tid=0x02242c00 nid=0x17c0 runnable</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am new to scala.</p>
<p>while compiling &#8211; the compiler just hangs and java processes keeps growing. Any idea what&#8217;s going on?</p>
<p>C:\work\scala&gt;scala -d bin src/com/codecommit/examples/*.scala<br />
2009-09-24 14:19:10<br />
Full thread dump Java HotSpot(TM) Client VM (11.3-b02 mixed mode, sharing):</p>
<p>&#8220;Low Memory Detector&#8221; daemon prio=6 tid=0&#215;0225d400 nid=0&#215;10d4 runnable [0x00000000..0x00000000]<br />
   java.lang.Thread.State: RUNNABLE</p>
<p>&#8220;CompilerThread0&#8243; daemon prio=10 tid=0&#215;0225a400 nid=0xf7c waiting on condition [0x00000000..0x0444fa10]<br />
   java.lang.Thread.State: RUNNABLE</p>
<p>&#8220;Attach Listener&#8221; daemon prio=10 tid=0&#215;02259800 nid=0&#215;8a4 runnable [0x00000000..0x00000000]<br />
   java.lang.Thread.State: RUNNABLE</p>
<p>&#8220;Signal Dispatcher&#8221; daemon prio=10 tid=0&#215;0224ec00 nid=0&#215;31c waiting on condition [0x00000000..0x00000000]<br />
   java.lang.Thread.State: RUNNABLE</p>
<p>&#8220;Finalizer&#8221; daemon prio=8 tid=0&#215;02246000 nid=0&#215;1050 in Object.wait() [0x0435f000..0x0435fa68]<br />
   java.lang.Thread.State: WAITING (on object monitor)<br />
        at java.lang.Object.wait(Native Method)<br />
        &#8211; waiting on  (a java.lang.ref.ReferenceQueue$Lock)<br />
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)<br />
        &#8211; locked  (a java.lang.ref.ReferenceQueue$Lock)<br />
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)<br />
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)</p>
<p>&#8220;Reference Handler&#8221; daemon prio=10 tid=0&#215;02244c00 nid=0xf9c in Object.wait() [0x00ddf000..0x00ddfae8]<br />
   java.lang.Thread.State: WAITING (on object monitor)<br />
        at java.lang.Object.wait(Native Method)<br />
        &#8211; waiting on  (a java.lang.ref.Reference$Lock)<br />
        at java.lang.Object.wait(Object.java:485)<br />
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)<br />
        &#8211; locked  (a java.lang.ref.Reference$Lock)</p>
<p>&#8220;main&#8221; prio=6 tid=0&#215;000ea000 nid=0&#215;1234 runnable [0x0039f000..0x0039fe28]<br />
   java.lang.Thread.State: RUNNABLE<br />
        at java.net.PlainSocketImpl.socketConnect(Native Method)<br />
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)<br />
        &#8211; locked  (a java.net.SocksSocketImpl)<br />
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)<br />
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)<br />
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)<br />
        at java.net.Socket.connect(Socket.java:519)<br />
        at java.net.Socket.connect(Socket.java:469)<br />
        at java.net.Socket.(Socket.java:366)<br />
        at java.net.Socket.(Socket.java:209)<br />
        at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:210)<br />
        at scala.tools.nsc.CompileSocket.getsock$1(CompileSocket.scala:224)<br />
        at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:227)<br />
        at scala.tools.nsc.CompileSocket.getOrCreateSocket(CompileSocket.scala:232)<br />
        at scala.tools.nsc.ScriptRunner$.compileWithDaemon(ScriptRunner.scala:237)<br />
        at scala.tools.nsc.ScriptRunner$.compile$1(ScriptRunner.scala:315)<br />
        at scala.tools.nsc.ScriptRunner$.withCompiledScript(ScriptRunner.scala:350)<br />
        at scala.tools.nsc.ScriptRunner$.runScript(ScriptRunner.scala:413)<br />
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:168)<br />
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)</p>
<p>&#8220;VM Thread&#8221; prio=10 tid=0&#215;02242c00 nid=0&#215;17c0 runnable</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4865</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 24 Jul 2009 20:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4865</guid>
		<description>@Taylor

No, it&#039;s not as bad as all that.  Scala builds are no more complicated than Java builds.  In fact, all of the same tools work in just about the same way.  Ant, Maven, Buildr (my personal favorite).  None of them have any trouble with Scala&#039;s unrestricted file conventions.</description>
		<content:encoded><![CDATA[<p>@Taylor</p>
<p>No, it&#8217;s not as bad as all that.  Scala builds are no more complicated than Java builds.  In fact, all of the same tools work in just about the same way.  Ant, Maven, Buildr (my personal favorite).  None of them have any trouble with Scala&#8217;s unrestricted file conventions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Taylor</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4863</link>
		<dc:creator>Taylor</dc:creator>
		<pubDate>Fri, 24 Jul 2009 20:25:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4863</guid>
		<description>&quot;Experienced Java developers will know the value of this convention, especially on a larger project&quot;

Nope, they&#039;ll get a stomach ache and wonder why they need to know anything about wher the files are located.  For years now I&#039;ve not thought twice about where the files are located, and where the .class is generated.  I don&#039;t care...the IDE worries about that for me.  By using Scala am I agreeing to take on the responsibility once again of wrangling files together, worrying about directory structures, and building my own make files as I once did with C/C++ apps and GCC?</description>
		<content:encoded><![CDATA[<p>&#8220;Experienced Java developers will know the value of this convention, especially on a larger project&#8221;</p>
<p>Nope, they&#8217;ll get a stomach ache and wonder why they need to know anything about wher the files are located.  For years now I&#8217;ve not thought twice about where the files are located, and where the .class is generated.  I don&#8217;t care&#8230;the IDE worries about that for me.  By using Scala am I agreeing to take on the responsibility once again of wrangling files together, worrying about directory structures, and building my own make files as I once did with C/C++ apps and GCC?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: harry</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4822</link>
		<dc:creator>harry</dc:creator>
		<pubDate>Sun, 12 Apr 2009 09:31:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4822</guid>
		<description>I&#039;m pretty sure Java itself doesn&#039;t enforce putting your source in directories with the same package structure, or that classes even have to be in a Java file of the same name. I&#039;ve had to fix code that doesn&#039;t, not because it wouldn&#039;t compile, but tracking the build dependencies was a lot harder.</description>
		<content:encoded><![CDATA[<p>I&#8217;m pretty sure Java itself doesn&#8217;t enforce putting your source in directories with the same package structure, or that classes even have to be in a Java file of the same name. I&#8217;ve had to fix code that doesn&#8217;t, not because it wouldn&#8217;t compile, but tracking the build dependencies was a lot harder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4027</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Sun, 14 Sep 2008 20:17:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4027</guid>
		<description>Unfortunately, if we use fields in Java, then we are obviating any possibility of overriding in the future.  Any references to those fields are *statically* bound to the class in which they are declared.  Additionally, if we want to add any value checks to the assignment semantics or perhaps change the data representation, we are sort of stuck with Java fields.  This contrasts with Scala&#039;s field semantics which are far more flexible.  Specifically, Scala &quot;fields&quot; are really more like syntactic sugar around methods.  The compiler is able to slip-stream some of this for optimization purposes, but at the language level, fields == methods.  Thus, the Scala version of Complex directly corresponds with all of the flexibility of the Java version (with getters and setters).  The Java version with only fields is more constrained.</description>
		<content:encoded><![CDATA[<p>Unfortunately, if we use fields in Java, then we are obviating any possibility of overriding in the future.  Any references to those fields are *statically* bound to the class in which they are declared.  Additionally, if we want to add any value checks to the assignment semantics or perhaps change the data representation, we are sort of stuck with Java fields.  This contrasts with Scala&#8217;s field semantics which are far more flexible.  Specifically, Scala &#8220;fields&#8221; are really more like syntactic sugar around methods.  The compiler is able to slip-stream some of this for optimization purposes, but at the language level, fields == methods.  Thus, the Scala version of Complex directly corresponds with all of the flexibility of the Java version (with getters and setters).  The Java version with only fields is more constrained.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Akintayo A. Olusegun</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2/comment-page-1#comment-4026</link>
		<dc:creator>Akintayo A. Olusegun</dc:creator>
		<pubDate>Sun, 14 Sep 2008 19:01:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-2#comment-4026</guid>
		<description>public class Complex {
    private int a, b;
 
    public Complex(int a, int b) {
        this.a = a;
        this.b = b;
    }
 
    public int getA() {
        return a;
    }
 
    public void setA(int a) {
        this.a = a;
    }
 
    public int getB() {
        return b;
    }
 
    public void setB(int b) {
        this.b = b;
    }
}
 
// ...
final Complex number = new Complex(1, 0);
number.setB(12);

I totally disagree with this. Although java is verbose(which is why I am looking at scala), but I guess if I do this is scala

class Complex(var a:Int, var b:Int)
 
// ...
val number = new Complex(1, 0)
number.b = 12

what I am saying in java terms is Complex has two public members, a and b

so in java we have

public class Complex {
  public int a;
  public int b;
//I dont need a contructor
}

Complex complex = new Complex();
complex.a = 12;
//.....etc
Still more verbose...but you get my point</description>
		<content:encoded><![CDATA[<p>public class Complex {<br />
    private int a, b;</p>
<p>    public Complex(int a, int b) {<br />
        this.a = a;<br />
        this.b = b;<br />
    }</p>
<p>    public int getA() {<br />
        return a;<br />
    }</p>
<p>    public void setA(int a) {<br />
        this.a = a;<br />
    }</p>
<p>    public int getB() {<br />
        return b;<br />
    }</p>
<p>    public void setB(int b) {<br />
        this.b = b;<br />
    }<br />
}</p>
<p>// &#8230;<br />
final Complex number = new Complex(1, 0);<br />
number.setB(12);</p>
<p>I totally disagree with this. Although java is verbose(which is why I am looking at scala), but I guess if I do this is scala</p>
<p>class Complex(var a:Int, var b:Int)</p>
<p>// &#8230;<br />
val number = new Complex(1, 0)<br />
number.b = 12</p>
<p>what I am saying in java terms is Complex has two public members, a and b</p>
<p>so in java we have</p>
<p>public class Complex {<br />
  public int a;<br />
  public int b;<br />
//I dont need a contructor<br />
}</p>
<p>Complex complex = new Complex();<br />
complex.a = 12;<br />
//&#8230;..etc<br />
Still more verbose&#8230;but you get my point</p>
]]></content:encoded>
	</item>
</channel>
</rss>
