2013年10月29日星期二

Java Novice

private Yujingpz_serv srv = null;
public Yujingpz_json () {
srv = new Yujingpz_serv ();
}
Why should it be so ?
written like this , what is wrong ? private Yujingpz_serv srv = new Yuingpz_serv ();
------ Solution -------------- ------------------------------
your wording is direct initialization ,
And earlier in the call to the constructor method when it is initialized , say lazy loading is similar to the form , the performance was slightly better . Theoretical than practical significance . Initializes a small object , the JVM is a small case, unless you are a member of this domain is a big object, there are obvious benefits of the former . Little difference between the two . General situation can be generic, specific code structure , and performance requirements.
essentially little difference between the landlord not to tangle here .

------ For reference only ---------------------------------- -----
private Yujingpz_serv srv = null;
public Yujingpz_json () {
srv = new Yujingpz_serv ();
}

above if I do not call the constructor , then srv will not be initialized.

you that the wording directly initialized
------ For reference only --------------------------- ------------
see what you need. A constructor is needed .
------ For reference only -------------------------------------- -
you if coupled with the code : private Yujingpz_json () {}
This is a single case of it.
------ For reference only -------------------------------------- -

rookie not understand, so the next question .

没有评论:

发表评论