与 Java 中的字面术语混淆

发布于 2024-12-02 04:41:44 字数 53 浏览 2 评论 0原文

我总是遇到字面这个词。 那是什么?

是不是每个原始类型变量都被称为文字变量?

I always come across the term literal.
What is that?

Is it that every primitive type variable is called as literal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

俯瞰星空 2024-12-09 04:41:44

文字是代码中使用的任何固定、常量值。

例如:
整数a=0;

0 是一个文字。 “0”的值实际上是 0。

Literal is any value, fixed, constant, used in your code.

For example:
int a =0 ;

0 is a literal. The value of "0" is literally 0.

风渺 2024-12-09 04:41:44

Java 语言规范 §3.10

文字是原始类型(第 4.2 节)、字符串类型(第 4.3.3 节)或空类型(第 4.1 节)的值的源代码表示形式...

Java Language Specification §3.10:

A literal is the source code representation of a value of a primitive type (§4.2), the String type (§4.3.3), or the null type (§4.1)...

手心的温暖 2024-12-09 04:41:44

文字是一个用引号括起来的字符串 - 基本上是一个字符串本身,而不是一个变量:

string variable = "This is the Literal section of the string";

这使得字符串变量和字符串文字。您的代码中需要变量,但您希望将文字删除到外部文件中,因此它们不会随应用程序一起编译,您可以即时更改它们。

A literal is a string that is in quotes - basically a string in and of itself, not in a variable:

string variable = "This is the literal section of the string";

This makes the distinction between a string variable and a string literal. You need variables in your code, but you would like to remove literals out to an external file, so they are not compiled with the application and you can change them on the fly.

苍风燃霜 2024-12-09 04:41:44

归根结底,就是在不使用 new 关键字(或引用已经存在的对象)的情况下为变量赋值。

请参阅 Oracle 关于原始数据类型的教程。尽管这些天我尝试引用 Oracle,但其他答案中的引用似乎更详尽(例如也指出 true 和 false)。

干杯,
维姆

It comes down to assigning a value to a variable without the use of the new keyword (or referring to an already existing object).

See Oracle's tutorial on primitive datatypes. Even though I'd try to refer to Oracle these days, the references in the other answers seem to be more exhaustive (also pointing to true and false for example).

Cheers,
Wim

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文