gpt4 book ai didi

Java变量声明当前标准

转载 作者:行者123 更新时间:2023-11-30 06:11:34 25 4
gpt4 key购买 nike

我很快就会尝试我的 OCA,并且我一直在获得有关如何正确声明 Longs 和 Floats 的混合信息。

从 JavaSE8 开始,如何正确声明一个 Long 和一个 Float,就像在转换值末尾附加 L 或 F 一样,或者这不再是必需的?

最佳答案

对于 long 字面量,您应该使用 L,对于 float 字面量,无论与 有什么不同,都应该使用 F intdouble 很重要。 Always 是一种很好的保护措施,可以防止在重要的时候忘记。

Integer Literals 引用 Java 8 语言规范:

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).

The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

Floating-Point Literals :

A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d (§4.2.3).

关于Java变量声明当前标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33946063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com