Java变量初始化?
这种类型的初始化是什么:以下
long i=12l; //using 'l' to denote long variable
double d=12.0d; //using 'd' to denote double variable
之间有区别吗:
long i=12l;
and
long i=12L;
What is this type of initialization know as:
long i=12l; //using 'l' to denote long variable
double d=12.0d; //using 'd' to denote double variable
Is there a difference between:
long i=12l;
and
long i=12L;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些只是在同一语句中声明和初始化变量,并使用 literals 提供初始值。
第二个片段中的两个语句之间没有任何区别 - 除了可读性之外。 “L”更容易读,因为它看起来一点也不像“1”。 (Java Puzzlers 之一就是基于此 - 显然整本书的字体选择让这个谜题变得更加困难。)
These are just declaring and initializing a variable in the same statement, and using literals to supply the initial values.
There's no difference between the two statements in the second snippet - except for readability. It's much easier to read "L" because it looks nothing like a "1". (One of the Java Puzzlers is based on this - and apparently the whole book's font was chosen to make that puzzle even harder.)