当前位置: 首页>>代码示例>>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;未经允许,请勿转载。