Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Answer to Tomasz Nurkiewicz @ http://stackoverflow.com/questions/9619416/scala-implictly-convert-a-list
- You only move the problem to the call site :/
- As for elegance, I am interested in your opinion. The context is that I am building a compiler and have a mapping between identifiers and "identifiable objects" such as variables and types. So I have an Identifiable class and Variable, Type subclasses. When I lookup and identifier, I sometimes want to get a Type, sometimes a Variable. What I do is define implicit conversion from Identifiable to the subclasses, which check the types with "isInstanceOf". In case of mismatch (e.g. I get a variable when I want a type) I throw an exception, which will be caught upstream and converted to a compile error.
- Do you think there's a more elegant way to do this ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement