java java中数据类型的默认值是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44151017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is default values for data type in java?
提问by Dhiraj Kumar
i am very new to java having always issue with data types so What is the Default values for all datatypes in java.?
我对 java 很陌生,总是有数据类型的问题,所以 java 中所有数据类型的默认值是什么?
回答by chamina
byte 0
short 0
int 0
long 0
float 0.0f
double 0.0d
char '\u0000'
boolean false
回答by Dhiraj Thakur
http://javaignite.com/post/66/default-values-for-primitives-in-java
http://javaignite.com/post/66/default-values-for-primitives-in-java
primitives dont have null value. default have for an int is 0.
原语没有空值。int 的默认值为 0。
if(person.getId()==0){}
Default values for primitives in java:
java中基元的默认值:
Data Type Default Value (for fields)
数据类型默认值(用于字段)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
boolean false
Objects have null as default value.
对象的默认值是 null。