This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Scala and the fly likes What's the value of case class X(x:Int)(y:String) vs case class X(x:Int, y:String)? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Languages » Scala
Reply Bookmark "What Watch "What New topic
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!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: What's the value of case class X(x:Int)(y:String) vs case class X(x:Int, y:String)?
 
Similar Threads
Method Syntax
How do i 'curry' in scala
need to run threads with different parameters
def vs val
The fizz buzz coding challenge