最近(2016年10月,OP后六年),
Richard Dallaway的博客文章“
Scala and 22”探讨了这个限制:
Back in 2014,when Scala 2.11 was released,an important limitation was removed:
Case classes with > 22 parameters are now allowed.
This may lead you to think there are no 22 limits in Scala,but that’s not the case. The limit lives on in functions and tuples.
The fix (07002) introduced in Scala 2.11 removed the limitation for the above common scenarios: constructing case classes,field access (including copying),and pattern matching (07003).
It did this by omitting unapply
and tupled
for case classes above 22 fields.
In other words,the limit to 07004 and 07005 still exists.
Working around the Limit (post Scala 2.11)
There are two common tricks for getting around this limit.
-
The first is to use nested tuples.
Although it’s true a tuple can’t contain more than 22 elements,each element itself could be a tuple
-
The other common trick is to use heterogeneous lists (HLists),where there’s no 22 limit.
If you want to make use of case classes,you may be better off using the shapeless HList implementation. We’ve created the 07006 to make that easier. In particular 07007 converts between shapeless HLists
and case classes. It looks like this:
import slick.driver.H2Driver.api._
import shapeless._
import slickless._
class LargeTable(tag: Tag) extends Table[Large](tag,"large") {
def a = column[Int]("a")
def b = column[Int]("b")
def c = column[Int]("c")
/* etc */
def u = column[Int]("u")
def v = column[Int]("v")
def w = column[Int]("w")
def * = (a :: b :: c :: /* etc */ :: u :: v :: w :: HNil)
.mappedWith(Generic[Large])
}
There’s a 07008 in the Slickless code base.