Suppose I have a static variable in a class:
class Example {
public static var one:One = new One;
}
Will ‘one’ being instanciated at my program startup (even if I never use it), or just at the first time I use it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I guess if you ask the question, it’s because you only want the object to be created if you use it. In that case, what you should do is implement lazy creation of the object. Something like that would work:
Now you are sure that
onewill only be created if you directly refers to it usingExample.onein your code.