Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable default value

"It is important to point out that the content field of the template is by default set to null (as Java does with all noninitialized object fields upon creation)."

It is from book "JavaSpaces Principles Patterns and Practice"

Here is code:

public class Message implements Entry {
  public String content;
  public Message() {
  }
}

I wonder if this is true, because I watched somewhere on internet that this is not true?

like image 925
Иван Бишевац Avatar asked Dec 21 '22 10:12

Иван Бишевац


1 Answers

Yes, this is true, but it may not mean quite what you think it means. All object fields will be initialized to null if no value is specified, but primitive types have other default values. For instance, int fields default to 0, floats to 0.0, and booleans to false.

More information on these defaults here: http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html.

like image 185
kylc Avatar answered Jan 02 '23 23:01

kylc