小编Muz*_*fer的帖子

初始化Gson对象的最佳方法

出于以下两个选项,您更喜欢哪一个初始化Gson对象?有人可以帮我理解这两种方式对Android应用程序性能的影响(启动时间?),如果有的话.

// inline creation
private final Gson gson = new Gson();
Run Code Online (Sandbox Code Playgroud)

VS

// need base creation, overhead of sync everytime while accessing gson object
private synchronized Gson getOrCreateGson() {
    gson == null ? gson = new Gson() : gson;
    return gson.fromJson(jsonString, clazz);
}
Run Code Online (Sandbox Code Playgroud)

java performance android gson

5
推荐指数
1
解决办法
4466
查看次数

标签 统计

android ×1

gson ×1

java ×1

performance ×1