Scala has the StringLike trait. Let's say I want to create a case class Name
and internally it should save the name with some characters. Should I use case class Name(name: StringLike)
or case class Name(name: String)
?
The former is obviously more abstract. It means someone can give me CustomString
that extends StringLike
and he might overwrite some methods.
If I want to be sure the given argument behaves like the String
class I know, I should use String
and else StringLike
. Is that correct? Are there cases in which it would make a practically difference?
Also, are there things I can do with the more specialized String
that I can't do with a StringLike
?