| Author |
What's the value of case class X(x:Int)(y:String) vs case class X(x:Int, y:String)?
|
Jacek Laskowski
Ranch Hand
Joined: Nov 06, 2005
Posts: 34
|
|
Hi,
I've been running into it quite often, but can't find the answer - why would one use two or more constructor's parameter lists over one? When is case class X(x:Int)(y:String) better than case class X(x:Int, y:String)? I'd highly appreciate samples of their use cases.
Jacek
|
Jacek Laskowski - http://blog.japila.pl
|
 |
Konrad Malawski
Greenhorn
Joined: Feb 26, 2013
Posts: 1
|
|
Hello Jacek, you've made me to register here so I could reply ;-)
To start out, I've never seen anyone using a case class with multiple parameter lists.
Back to what it actually does, first the normal syntax:
And let's investigate what your ()() syntax does to a case class:
Let's take a look at it's apply (B$ is the companion object of B):
So well... I don't see any reason why one would use the second syntax you proposed.
It makes a lot of sense for methods (it's for currying there), but definitely not for case classes - keep 'em simple :-)
Where did you bump into code using ()() in case classes? I can imagine using an implicit parameter list there, but otherwise I see no use case that appeals to me.
|
GeeCON.org - Let's move the Java world!
|
 |
 |
|
|
subject: What's the value of case class X(x:Int)(y:String) vs case class X(x:Int, y:String)?
|
|
|