有没有办法使用“类型"?word 作为 Scala 中的变量名? [英] Is there a way to use "type" word as a variable name in Scala?

查看:22
本文介绍了有没有办法使用“类型"?word 作为 Scala 中的变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的实践中,变量/参数经常用于存储某种类型的东西(通常作为枚举值).并且在名称中指定实体类通常是没有意义的(例如,当函数用于处理用户时,就像 userType 一样).有没有一种方法可以根据我的需要使用类型"一词,而不是使用像tipe"、kind"、somethingType"这样的脚手架来代替它?实际的 Scala type 关键字很少使用 - 如果我可以在我的大多数代码文件中取消定义它(作为关键字),那就太好了.

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.

推荐答案

你可以用反引号转义:

val `type` = 5

这篇关于有没有办法使用“类型"?word 作为 Scala 中的变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆