语法特征“long foo = 12L”的技术名称是什么? Java 中硬编码值的样式转换?
今天,我试图将一个硬编码值投射到一个短片中,但 S 不起作用。 于是,我去搜索了一下,结果发现我根本不知道Java语法的这个特性叫什么。 它有名字吗? 如果没有,是否至少有一个列表,列出了所有可能的硬编码数值转换方法?
Epilouge
在得到答案“Literals”后,我能够回答关于短裤的问题。 如果您想知道的话,Java 中没有短文本。 您只需将其显式转换为:(short)12
。
Today, I was trying to cast a hard-coded value into a short and S did not work. So, I went to search for it, but I realized that I do not even know what this feature of Java's syntax is called. Is there a name for it? If not, is there at least a list of all of the possible ways to cast hard-coded numeric values?
Epilouge
After getting the answer "Literals", I was able to answer my question about shorts. In case you are wondering, there is no short literal in Java. You just have to explicitly cast it as so: (short)12
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们被称为文字。
来自 Java 教程的原始数据类型页面:
有一个可以在原始数据类型中使用的文字列表“文字”部分下的 页面。
第 3.10 节:文字 href="http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html" rel="nofollow noreferrer">Java 语言规范,第三版 也有完整的列表。
They are called literals.
From the Primitive Data Types page of The Java Tutorials:
There's a list of literals that can be used in the Primitive Data Types page under the Literals section.
Section 3.10: Literals of the Java Language Specification, Third Edition has a complete list as well.