What does "The default initialization of any object happens-before any other actions (other than default- writes) of a program" mean?

StackOverflow https://stackoverflow.com/questions/19121527

  •  30-06-2022
  •  | 
  •  

문제

Java Language Specification 7, section 17.4.5:

5. The default initialization of any object happens-before any other
actions (other than default-writes) of a program.

What does it exactly mean? What is default initialization? Can you provide some examples?

도움이 되었습니까?

해결책 2

Default initialization is process of assigning the instance's fields to their respective default values.

That section you've quoted tells you this happens before, for example, the constructor is called.

다른 팁

Happens-before is a concurrency term. At face value, it means what you think, but it goes beyond that. For non-final, non-volatile fields, Java doesn't guarantee that the field values will by synced across threads unless something establishes a happens-before relationship.

That part of the spec means that other threads accessing the object will see the default initialization values, even if you spawn a thread in the constructor.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top