當前位置: 首頁>>代碼示例>>Java>>正文


Java InstanceCreator.createInstance方法代碼示例

本文整理匯總了Java中com.google.gson.InstanceCreator.createInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java InstanceCreator.createInstance方法的具體用法?Java InstanceCreator.createInstance怎麽用?Java InstanceCreator.createInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.InstanceCreator的用法示例。


在下文中一共展示了InstanceCreator.createInstance方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConstructor

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
public <T> ObjectConstructor<T> getConstructor(TypeToken<T> typeToken) {
    final Type type = typeToken.getType();
    Class<? super T> rawType = typeToken.getRawType();
    final InstanceCreator<T> creator = (InstanceCreator) this.instanceCreators.get(type);
    if (creator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return creator.createInstance(type);
            }
        };
    }
    ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
    if (defaultConstructor != null) {
        return defaultConstructor;
    }
    ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(rawType);
    if (defaultImplementation != null) {
        return defaultImplementation;
    }
    return newUnsafeAllocator(type, rawType);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:ConstructorConstructor.java

示例2: get

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken) {
    final Type type = typeToken.getType();
    Class<? super T> rawType = typeToken.getRawType();
    final InstanceCreator<T> typeCreator = (InstanceCreator) this.instanceCreators.get(type);
    if (typeCreator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return typeCreator.createInstance(type);
            }
        };
    }
    final InstanceCreator<T> rawTypeCreator = (InstanceCreator) this.instanceCreators.get
            (rawType);
    if (rawTypeCreator != null) {
        return new ObjectConstructor<T>() {
            public T construct() {
                return rawTypeCreator.createInstance(type);
            }
        };
    }
    ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
    if (defaultConstructor != null) {
        return defaultConstructor;
    }
    ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(type,
            rawType);
    if (defaultImplementation != null) {
        return defaultImplementation;
    }
    return newUnsafeAllocator(type, rawType);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:ConstructorConstructor.java

示例3: createInstance

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
/**
 * Hook for the graph adapter to get a reference to a deserialized value
 * before that value is fully populated. This is useful to deserialize
 * values that directly or indirectly reference themselves: we can hand
 * out an instance before read() returns.
 *
 * <p>
 * Gson should only ever call this method when we're expecting it to;
 * that is only when we've called back into Gson to deserialize a tree.
 */
@SuppressWarnings("unchecked")
public Object createInstance(Type type) {
    Graph graph = graphThreadLocal.get();
    if (graph == null || graph.nextCreate == null) {
        throw new IllegalStateException("Unexpected call to createInstance() for " + type);
    }
    InstanceCreator<?> creator = instanceCreators.get(type);
    Object result = creator.createInstance(type);
    graph.nextCreate.value = result;
    graph.nextCreate = null;
    return result;
}
 
開發者ID:sap-nocops,項目名稱:Jerkoff,代碼行數:23,代碼來源:GraphAdapterBuilder.java

示例4: getConstructor

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
public <T> ObjectConstructor<T> getConstructor(TypeToken<T> typeToken) {
  final Type type = typeToken.getType();
  final Class<? super T> rawType = typeToken.getRawType();

  // first try an instance creator

  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> creator = (InstanceCreator<T>) instanceCreators.get(type);
  if (creator != null) {
    return new ObjectConstructor<T>() {
      public T construct() {
        return creator.createInstance(type);
      }
    };
  }

  ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
  if (defaultConstructor != null) {
    return defaultConstructor;
  }

  ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(rawType);
  if (defaultImplementation != null) {
    return defaultImplementation;
  }

  // finally try unsafe
  return newUnsafeAllocator(type, rawType);
}
 
開發者ID:appcelerator-archive,項目名稱:ti.box,代碼行數:30,代碼來源:ConstructorConstructor.java

示例5: get

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken) {
  final Type type = typeToken.getType();
  final Class<? super T> rawType = typeToken.getRawType();

  // first try an instance creator

  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> typeCreator = (InstanceCreator<T>) instanceCreators.get(type);
  if (typeCreator != null) {
    return new ObjectConstructor<T>() {
      public T construct() {
        return typeCreator.createInstance(type);
      }
    };
  }

  // Next try raw type match for instance creators
  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> rawTypeCreator =
      (InstanceCreator<T>) instanceCreators.get(rawType);
  if (rawTypeCreator != null) {
    return new ObjectConstructor<T>() {
      public T construct() {
        return rawTypeCreator.createInstance(type);
      }
    };
  }

  ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
  if (defaultConstructor != null) {
    return defaultConstructor;
  }

  ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(type, rawType);
  if (defaultImplementation != null) {
    return defaultImplementation;
  }

  // finally try unsafe
  return newUnsafeAllocator(type, rawType);
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:42,代碼來源:ConstructorConstructor.java

示例6: get

import com.google.gson.InstanceCreator; //導入方法依賴的package包/類
public <T> ObjectConstructor<T> get(TypeToken<T> typeToken) {
  final Type type = typeToken.getType();
  final Class<? super T> rawType = typeToken.getRawType();

  // first try an instance creator

  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> typeCreator = (InstanceCreator<T>) instanceCreators.get(type);
  if (typeCreator != null) {
    return new ObjectConstructor<T>() {
      @Override public T construct() {
        return typeCreator.createInstance(type);
      }
    };
  }

  // Next try raw type match for instance creators
  @SuppressWarnings("unchecked") // types must agree
  final InstanceCreator<T> rawTypeCreator =
      (InstanceCreator<T>) instanceCreators.get(rawType);
  if (rawTypeCreator != null) {
    return new ObjectConstructor<T>() {
      @Override public T construct() {
        return rawTypeCreator.createInstance(type);
      }
    };
  }

  ObjectConstructor<T> defaultConstructor = newDefaultConstructor(rawType);
  if (defaultConstructor != null) {
    return defaultConstructor;
  }

  ObjectConstructor<T> defaultImplementation = newDefaultImplementationConstructor(type, rawType);
  if (defaultImplementation != null) {
    return defaultImplementation;
  }

  // finally try unsafe
  return newUnsafeAllocator(type, rawType);
}
 
開發者ID:MyJojoX,項目名稱:MyJojoXUtils,代碼行數:42,代碼來源:ConstructorConstructor.java


注:本文中的com.google.gson.InstanceCreator.createInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。