KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
So here's the situation. I want to define a case class like so: case class A(val s: String) and I want to define an object to ensure that when I create instances of the class, the value for 's' is always uppercase, like so: object A { def apply(s: String) = new A(s.toUpperCase) } However, this doesn't work since Scala is complaining that the apply(s: String) method is defined twice. I understand that the case class syntax will automatically define it for me, but isn't there another way I can achieve this? I'd like to stick with the case class since I want to use it for pattern matching.
Tags (comma-separated)
Save Edits
Cancel