- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
types of strings
Sun, 2011-12-18, 15:36
i regularly encounter situations where strings are used. for example it
might be an url. or a resource key. or a string that is supposed to be
sent to a brower and has to be escaped.
and i regularly see errors caused by the fact that you cannot ask a
string if it has already been resolved (if it's a resource key) or
escaped, or if it is a relative or absolute url. if it even is one.
in java, i try to make this a bit safer by creating simple wrappers like
"class ResourceKey(val key:String)" to make sure i don't accidently mix
them up. is there a way to achieve this in scala without wrapper
classes? can i somehow (mis)use abstract types for this?
basically i want to say :
type AbsoluteUrl = ???
def iAmAbsolutelySureThisIsAnAbsoluteUrl(url:String) =