Is there a way to use “type” word as a variable na

2019-01-15 17:39发布

问题:

It is frequent in my practice that a variable/argument is to store a type of something (as an enumeration value usually). And it usually makes no sense to specify an entity class in the name (like userType when a function is onlu intended to handle users). Is there a way I can use the "type" word for my needs instead of using scaffolds like "tipe", "kind", "somethingType" instead of it? The actual Scala type keyword is of such a rare use - it would be nice If I could undefine it (as a keyword) in the most of my code files.

回答1:

You can escape with backticks:

val `type` = 5


标签: scala keyword