Is there a way to use “type” word as a variable name in Scala?

旧城冷巷雨未停 提交于 2019-11-27 04:49:12

问题


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


来源:https://stackoverflow.com/questions/8198797/is-there-a-way-to-use-type-word-as-a-variable-name-in-scala

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!