Saturday, 14 September 2013

Scala Type Parameter and Case Classes

Scala Type Parameter and Case Classes

I have a function like this:
private def fixBrand[T]( item:T ) = item.copy(brand = item.brand.toLowerCase)
This isn't compiling---complains T doesn't have function copy. Now I know
that every item I'll pass in is a case class. How can I tell the compiler?
Each of these case classes also have a 'brand' field, but are unrelated,
in terms of object hierarchy.
I thought I read that Scala 2.10 had a feature that allowed me to use T as
"a thing" that had function x, y, ...? Forgot what that feature was
called, though!
Thanks for any hints!
Greg

No comments:

Post a Comment