Java,一种使用保留字的方法 [英] Java, a way to use reserved words

查看:168
本文介绍了Java,一种使用保留字的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法允许您将关键字用作Java中的资源名称,类似于C#中在单词的开头加@的方法?

Is there a method that allows you to use a keyword as a resource name in Java similar to the method used in C# of adding @ to the start of the word?

几年前,我发现一些帖子对此提出了要求,但那时是不可能的.是在Java 7中添加还是在Java 8中添加了?

I found some posts asking this a few years ago and it wasn't possible then. Was it possibly added though in Java 7 or may be added in Java 8?

这样做的原因非常稀缺.对我来说,虽然在反序列化使用关键字作为变量名的大型json对象时遇到过它.我正在使用的特定json对象使用throw.在C#中,我只是将"string @throw"添加到用于反序列化对象的类中.我只能在Java中找到执行此操作的唯一方法,这将需要流式反序列化,这将是一个很大的麻烦,或者需要使用正则表达式进行字符串解析,这对于执行本来可以非常简单的任务来说似乎都是很多工作. /p>

Reasons for doing this are very scarce. For me though I've encountered it when deserializing large json objects that use the keywords as variable names. A particular json object I'm working with uses throw. In C# I'd just add "string @throw" into my class that I use to deserialize the object. The only methods I can find to do this in java would require a streaming deserialization which would be a major pain, or string parsing with Regular Expressions both of which seem to be a lot of work for what could otherwise be a super simple task.

推荐答案

否,这在Java中是不可能的.变量的名称
Java中的语言不能与任何关键字保留字一致.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts /_keywords.html

No, this is not possible in Java. The names of variables
in Java cannot coincide with any keywords or reserved words.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

这篇关于Java,一种使用保留字的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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