@SuppressWarnings("unchecked")
  public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {
    TypeAdapter<?> cached = typeTokenCache.get(type);
    if (cached != null) {
      return (TypeAdapter<T>) cached;
    }

    Map<TypeToken<?>, FutureTypeAdapter<?>> threadCalls = calls.get();
    // the key and value type parameters always agree
    FutureTypeAdapter<T> ongoingCall = (FutureTypeAdapter<T>) threadCalls.get(type);
    if (ongoingCall != null) {
      return ongoingCall;
    }

    FutureTypeAdapter<T> call = new FutureTypeAdapter<T>();
    threadCalls.put(type, call);
    try {
      for (TypeAdapterFactory factory : factories) {
        TypeAdapter<T> candidate = factory.create(this, type);
        if (candidate != null) {
          call.setDelegate(candidate);
          typeTokenCache.put(type, candidate);
          return candidate;
        }
      }
      throw new IllegalArgumentException("GSON cannot handle " + type);
    } finally {
      threadCalls.remove(type);
    }
  }
@SuppressWarnings("unchecked")
  public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {
    TypeAdapter<?> cached = typeTokenCache.get(type);
    if (cached != null) {
      return (TypeAdapter<T>) cached;
    }

    Map<TypeToken<?>, FutureTypeAdapter<?>> threadCalls = calls.get();
    
    FutureTypeAdapter<T> ongoingCall = (FutureTypeAdapter<T>) threadCalls.get(type);
    if (ongoingCall != null) {
      return ongoingCall;
    }

    FutureTypeAdapter<T> call = new FutureTypeAdapter<T>();
    threadCalls.put(type, call);
    try {
      for (TypeAdapterFactory factory : factories) {
        TypeAdapter<T> candidate = factory.create(this, type);
        if (candidate != null) {
          call.setDelegate(candidate);
          typeTokenCache.put(type, candidate);
          return candidate;
        }
      }
      throw new IllegalArgumentException("GSON cannot handle " + type);
    } finally {
      threadCalls.remove(type);
    }
  }
@ SuppressWarnings ( "unchecked" ) public < T > TypeAdapter < T > getAdapter ( TypeToken < T > type ) { TypeAdapter < ? > cached = typeTokenCache . get ( type ) ; if ( cached != null ) { return ( TypeAdapter < T > ) cached ; } Map < TypeToken < ? > , FutureTypeAdapter < ? > > threadCalls = calls . get ( ) ; // the key and value type parameters always agree FutureTypeAdapter < T > ongoingCall = ( FutureTypeAdapter < T > ) threadCalls . get ( type ) ; if ( ongoingCall != null ) { return ongoingCall ; } FutureTypeAdapter < T > call = new FutureTypeAdapter < T > ( ) ; threadCalls . put ( type , call ) ; try { for ( TypeAdapterFactory factory : factories ) { TypeAdapter < T > candidate = factory . create ( this , type ) ; if ( candidate != null ) { call . setDelegate ( candidate ) ; typeTokenCache . put ( type , candidate ) ; return candidate ; } } throw new IllegalArgumentException ( "GSON cannot handle " + type ) ; } finally { threadCalls . remove ( type ) ; } }
Returns the type adapter for {@code} type.

@throws IllegalArgumentException if this GSON cannot serialize and
deserialize {@code type}.
Returns the type adapter for { @code } type .