MCPcopy
hub / github.com/google/gson / create

Method create

gson/src/test/java/com/google/gson/GsonTest.java:187–213  ·  gson/src/test/java/com/google/gson/GsonTest.java::GsonTest.create
(Gson gson, TypeToken<T> type)

Source from the content-addressed store, hash-verified

185 private volatile boolean isFirstCall = true;
186
187 @Override
188 public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
189 if (isFirstCall) {
190 isFirstCall = false;
191
192 class="cm">// Create a separate thread which requests an adapter for the same type
193 class="cm">// This will cause this factory to return a different adapter instance than
194 class="cm">// the one it is currently creating
195 Thread thread =
196 new Thread() {
197 @Override
198 public void run() {
199 threadAdapter.set(gson.getAdapter(requestedType));
200 }
201 };
202 thread.start();
203 try {
204 thread.join();
205 } catch (InterruptedException e) {
206 throw new RuntimeException(e);
207 }
208 }
209
210 class="cm">// Create a new dummy adapter instance
211 adapterInstancesCreated.incrementAndGet();
212 return new DummyAdapter<>();
213 }
214 })
215 .create();
216

Callers

nothing calls this directly

Calls 2

getAdapterMethod · 0.80
getRawTypeMethod · 0.45

Tested by

no test coverage detected