#not defined string = null?
43 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @next sierra! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
No. (For fields):
String name = ""; // String with length 0
String name; // name is null
String name = null; // name is null
For local variables:
String name; // Variable is just not initialised. Using said variable without prior initilisation will return an exception at compile time.
String name = null; // Variable is initialised with the value null.
String name = "" // Same as fields
if int num;
num = null here?
String name; // name is null
I would add, that if it's field - then null, if local variable inside a method - it's not initialized (so it's not null too)
no, int can't be null, int defaults to 0
all the primitives default to an equivalent of 0
boolean - false
char - '\0'
byte, short, int, long - 0
float, double - 0.0
ty
it is null, it's just not allowed to be accessed
it's not initialised, no matter what is it's inner state.
but the
so it's not null too
isn't exactly correct
yeah, but still you can't do if (name == null)
yeah because that's accessing it...
so there is no matter of what it's inner state
it's... null though?
null or not
that's just how it is
god that sounds so much like the private inheritance discussion on the ts server the other day
can you give me practical example of usage not initialized (but inner null sate) of an object?
no, because it's expressly not meant to be used
im not arguing that it's initialized to null or whatever
but saying it definitely isn't null is wrong
can you use it? can you do if (anObject == null)? no. so no point of saying it's null or not. it's not initialised.
so no point of saying it's null or not.
so then why did you explicitly say "not null" if it doesn't matter?
because it has not initialised state
which is distinct and separate from the value
neither null or not null
no not how it works
did TC ask about JMM?
the "not definitely initialized" thing is a compiler thing, it doesn't deal with values
null is a value
I guess he asked about how it bahaves in practice
i am so confused about what you're asking here
Im not asking
who the hell is TC
topic creator
i mean this isn't really a topic so that doesn't really work but ok
anyways, this
it is uninitialized yes, but the underlying value would be null; it's just not accessible/readable
Actually, local variables that haven't been initialized don't exist beside the compiler knowing you want a variable
They're not null nor anything, they just aren't
Once you initialize them, the compiler knows you want a variable and will organize to have it on the stack, where, on the stack and once pushed, it will have a value
Before that, it's nothing