- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
why case class and its Companion object definition order matters?
Mon, 2011-04-25, 00:53
Is there any reason for which this
scala> { | object FF { def apply(id:Int,name:String):FF= FF(name) } | case class FF(name:String) | FF(1,"BB") | }
should be different from this?
scala> { | case class FF(name:String) | object FF { def apply(id:Int,name:String):FF= FF(name) } | FF(1,"BB") | }
--
www.sadekdrobi.com
ʎdoɹʇuǝ
scala> { | object FF { def apply(id:Int,name:String):FF= FF(name) } | case class FF(name:String) | FF(1,"BB") | }
should be different from this?
scala> { | case class FF(name:String) | object FF { def apply(id:Int,name:String):FF= FF(name) } | FF(1,"BB") | }
--
www.sadekdrobi.com
ʎdoɹʇuǝ
Mon, 2011-04-25, 01:17
#2
Re: why case class and its Companion object definition order ma
Even if I am submitting them all at once in a block? It seems to me that I had the problem outside the REPL but I can be mistaken.
On Mon, Apr 25, 2011 at 2:03 AM, Randall R Schulz <rschulz@sonic.net> wrote:
--
www.sadekdrobi.com
ʎdoɹʇuǝ
On Mon, Apr 25, 2011 at 2:03 AM, Randall R Schulz <rschulz@sonic.net> wrote:
On Sunday April 24 2011, Sadek Drobi wrote:
> Is there any reason for which this
>
> scala> {
>
> | object FF { def apply(id:Int,name:String):FF= FF(name) }
> | case class FF(name:String)
> | FF(1,"BB")
> | }
>
> should be different from this?
>
> scala> {
>
> | case class FF(name:String)
> | object FF { def apply(id:Int,name:String):FF= FF(name) }
> | FF(1,"BB")
> | }
REPL.
Any given sequence of Scala source-code bytes do not have the same
semantics in the REPL they do when compiled by scalac.
If you compiled those, there'd be no difference.
When you submit them to the REPL, the latter expression is in a
different scope than the earlier one and that scope is nested within
the earlier expression's scope.
Randall Schulz
--
www.sadekdrobi.com
ʎdoɹʇuǝ
Mon, 2011-04-25, 01:47
#3
Re: why case class and its Companion object definition order ma
On Sunday April 24 2011, Sadek Drobi wrote:
> Even if I am submitting them all at once in a block? It seems to me
> that I had the problem outside the REPL but I can be mistaken.
These two files both compile without a peep from scalac:
-==- OCC.scala -==-
object FF { def apply(id:Int,name:String):FF= FF(name) }
case class FF(name:String)
object OCC
{
def main(args: Array[String]) {
FF(1,"BB")
}
}
-==- OCC.scala -==-
-==- CCO.scala -==-
case class FF(name:String)
object FF { def apply(id:Int,name:String):FF= FF(name) }
object CCO {
def main(args: Array[String]) {
FF(1,"BB")
}
}
-==- CCO.scala -==-
Randall Schulz
Mon, 2011-04-25, 01:57
#4
Re: why case class and its Companion object definition order ma
Cool, I guess my other problem was about having companion and case class in different scopes in which case one would obviously shadow the other.
Thanks Randall.
On Mon, Apr 25, 2011 at 2:46 AM, Randall R Schulz <rschulz@sonic.net> wrote:
--
www.sadekdrobi.com
ʎdoɹʇuǝ
Thanks Randall.
On Mon, Apr 25, 2011 at 2:46 AM, Randall R Schulz <rschulz@sonic.net> wrote:
On Sunday April 24 2011, Sadek Drobi wrote:
> Even if I am submitting them all at once in a block? It seems to me
> that I had the problem outside the REPL but I can be mistaken.
These two files both compile without a peep from scalac:
-==- OCC.scala -==-
object FF { def apply(id:Int,name:String):FF= FF(name) }
case class FF(name:String)
object OCC
{
def main(args: Array[String]) {
FF(1,"BB")
}
}
-==- OCC.scala -==-
-==- CCO.scala -==-
case class FF(name:String)
object FF { def apply(id:Int,name:String):FF= FF(name) }
object CCO {
def main(args: Array[String]) {
FF(1,"BB")
}
}
-==- CCO.scala -==-
Randall Schulz
--
www.sadekdrobi.com
ʎdoɹʇuǝ
On Sunday April 24 2011, Sadek Drobi wrote:
> Is there any reason for which this
>
> scala> {
>
> | object FF { def apply(id:Int,name:String):FF= FF(name) }
> | case class FF(name:String)
> | FF(1,"BB")
> | }
>
> should be different from this?
>
> scala> {
>
> | case class FF(name:String)
> | object FF { def apply(id:Int,name:String):FF= FF(name) }
> | FF(1,"BB")
> | }
REPL.
Any given sequence of Scala source-code bytes do not have the same
semantics in the REPL they do when compiled by scalac.
If you compiled those, there'd be no difference.
When you submit them to the REPL, the latter expression is in a
different scope than the earlier one and that scope is nested within
the earlier expression's scope.
Randall Schulz