This is in continuation to my previous question and accroding to answers of this question Declaration of wrapper classes
Java wraps primitive data type to wrapper classes then why
char c = null; // invalid
int i = null; // invalid
is not allowed but
Character cObj = null; // valid
Integer iObj = null; // valid
is allowed.
Java primitive types (such as int , double , or float ) cannot have null values, which you must consider in choosing your result expression and host expression types.
Primitives (int, double, float, etc) are by definition not reference types, so they cannot have null values.
Summary. JavaScript has the primitive types: number , string , boolean , null , undefined , symbol and bigint and a complex type: object .
Answer is Object is superclass of all objects and can represent any user defined object. Since all primitives doesn't inherit from "Object" so we can't use it as a generic type.
Because primitives represent value and Object variables represent references (something like pointers) to complex data objects. There is no null value general, it is a special keyword that "references to nothing" or empty reference - this is highly unprofessional answer, but I guess it will be most appropriate.
Besides, what could be in your opinion, numerical value of null? 0? -1? But, those are valid integers so what else?
I strongly suggest that you start familiarizing yourself with the following complex java tutorial. Every aspect that you have been asking about is explained there and supported with examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With