Code Fragment-提前创建与懒创建。

来源:互联网 发布:淘宝详情页在哪里 编辑:程序博客网 时间:2024/06/09 22:58

提前加载,可以放在static{}中,当类被加载的时候创建,如:

static {    sURLMatcher.addURI("mms_temp_file", "scrapSpace", MMS_SCRAP_SPACE);}

懒加载,当被使用的时候再去创建

private void buildReadContentValues() {    if (mReadContentValues == null) {        mReadContentValues = new ContentValues(2);        mReadContentValues.put("read", 1);        mReadContentValues.put("seen", 1);    }}


类似的还有单例模式的不同创建方式:懒汉式,饿汉式。

原创粉丝点击