One of the most fundamental aspects of a programming language is how it initializes data. For Java, this is defined explicitly in the language . For fields and array components, when items are created, they are automatically set to the following default values by the system:
- numbers: 0 or 0.0
- booleans: false
- object references: null
This means that explicitly setting fields to 0, false, or null (as the case may be) is unnecessary and redundant. Since this language feature was included in order to, in part, reduce repetitive coding, it's a good idea to take full advantage of it. Insisting that fields should be explicitly initialized to 0, false, or null is an idiom which is likely inappropriate to the Java programming language.
_______________________________________________
Comments
Post a Comment