出于以下两个选项,您更喜欢哪一个初始化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)