com.google.inject.util.Types.newParameterizedType()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中com.google.inject.util.Types.newParameterizedType()方法的一些代码示例,展示了Types.newParameterizedType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.newParameterizedType()方法的具体详情如下:
包路径:com.google.inject.util.Types
类名称:Types
方法名:newParameterizedType

Types.newParameterizedType介绍

[英]Returns a new parameterized type, applying typeArguments to rawType. The returned type does not have an owner type.
[中]返回一个新的参数化类型,将typeArguments应用于rawType。返回的类型没有所有者类型。

代码示例

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a type modelling a {@link Set} whose elements are of type {@code elementType}.
 *
 * @return a {@link java.io.Serializable serializable} parameterized type.
 */
public static ParameterizedType setOf(Type elementType) {
 return newParameterizedType(Set.class, elementType);
}

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a type modelling a {@link List} whose elements are of type {@code elementType}.
 *
 * @return a {@link java.io.Serializable serializable} parameterized type.
 */
public static ParameterizedType listOf(Type elementType) {
 return newParameterizedType(List.class, elementType);
}

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a type modelling a {@link Provider} that provides elements of type {@code elementType}.
 *
 * @return a {@link java.io.Serializable serializable} parameterized type.
 */
public static ParameterizedType providerOf(Type providedType) {
 return newParameterizedType(Provider.class, providedType);
}

代码示例来源:origin: com.google.inject/guice

/**
  * Returns a type modelling a {@link javax.inject.Provider} that provides elements of type {@code
  * elementType}.
  *
  * @return a {@link java.io.Serializable serializable} parameterized type.
  */
 public static Type javaxProviderOf(Type type) {
  return Types.newParameterizedType(javax.inject.Provider.class, type);
 }
}

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a type modelling a {@link Collection} whose elements are of type {@code elementType}.
 *
 * @return a {@link java.io.Serializable serializable} parameterized type.
 */
public static ParameterizedType collectionOf(Type elementType) {
 return newParameterizedType(Collection.class, elementType);
}

代码示例来源:origin: com.google.inject/guice

/**
 * Returns a type modelling a {@link Map} whose keys are of type {@code keyType} and whose values
 * are of type {@code valueType}.
 *
 * @return a {@link java.io.Serializable serializable} parameterized type.
 */
public static ParameterizedType mapOf(Type keyType, Type valueType) {
 return newParameterizedType(Map.class, keyType, valueType);
}

代码示例来源:origin: com.google.inject/guice

@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<javax.inject.Provider<T>>> optionalOfJavaxProvider(
  TypeLiteral<T> type) {
 return (TypeLiteral<Optional<javax.inject.Provider<T>>>)
   TypeLiteral.get(
     Types.newParameterizedType(
       Optional.class, newParameterizedType(javax.inject.Provider.class, type.getType())));
}

代码示例来源:origin: com.google.inject/guice

@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<Provider<T>>> optionalOfProvider(TypeLiteral<T> type) {
 return (TypeLiteral<Optional<Provider<T>>>)
   TypeLiteral.get(
     Types.newParameterizedType(
       Optional.class, newParameterizedType(Provider.class, type.getType())));
}

代码示例来源:origin: apache/incubator-druid

@SuppressWarnings("unchecked")
public static <T> void bind(Binder binder, String propertyBase, Class<T> classToProvide)
{
 bind(
   binder,
   propertyBase,
   classToProvide,
   Key.get(classToProvide),
   (Key) Key.get(Types.newParameterizedType(Supplier.class, classToProvide))
 );
}

代码示例来源:origin: apache/incubator-druid

@SuppressWarnings("unchecked")
public static <T> void bind(Binder binder, String propertyBase, Class<T> classToProvide, Annotation annotation)
{
 bind(
   binder,
   propertyBase,
   classToProvide,
   Key.get(classToProvide, annotation),
   (Key) Key.get(Types.newParameterizedType(Supplier.class, classToProvide), annotation)
 );
}

代码示例来源:origin: apache/incubator-druid

public static <T> void bind(Binder binder, String key, Class<T> clazz, T defaultVal)
{
 binder.bind(Key.get(Types.newParameterizedType(Supplier.class, clazz)))
    .toProvider((Provider) of(key, clazz, defaultVal))
    .in(LazySingleton.class);
}

代码示例来源:origin: com.google.inject/guice

static <T> TypeLiteral<?> javaOptionalOfJavaxProvider(TypeLiteral<T> type) {
 checkState(JAVA_OPTIONAL_CLASS != null, "java.util.Optional not found");
 return TypeLiteral.get(
   Types.newParameterizedType(
     JAVA_OPTIONAL_CLASS,
     newParameterizedType(javax.inject.Provider.class, type.getType())));
}

代码示例来源:origin: com.google.inject/guice

static <T> TypeLiteral<?> javaOptionalOfProvider(TypeLiteral<T> type) {
 checkState(JAVA_OPTIONAL_CLASS != null, "java.util.Optional not found");
 return TypeLiteral.get(
   Types.newParameterizedType(
     JAVA_OPTIONAL_CLASS, newParameterizedType(Provider.class, type.getType())));
}

代码示例来源:origin: apache/incubator-druid

@SuppressWarnings("unchecked")
public static <T> void bind(
  Binder binder,
  String propertyBase,
  Class<T> classToProvide,
  Class<? extends Annotation> annotation
)
{
 bind(
   binder,
   propertyBase,
   classToProvide,
   Key.get(classToProvide, annotation),
   (Key) Key.get(Types.newParameterizedType(Supplier.class, classToProvide), annotation)
 );
}

代码示例来源:origin: apache/incubator-druid

@SuppressWarnings("unchecked")
public static <T> void bindWithDefault(
  Binder binder,
  String propertyBase,
  Class<T> classToProvide,
  Class<? extends T> defaultClass
)
{
 bind(
   binder,
   propertyBase,
   classToProvide,
   defaultClass,
   Key.get(classToProvide),
   (Key) Key.get(Types.newParameterizedType(Supplier.class, classToProvide))
 );
}

代码示例来源:origin: com.google.inject/guice

@SuppressWarnings("unchecked")
static <T> TypeLiteral<Optional<T>> optionalOf(TypeLiteral<T> type) {
 return (TypeLiteral<Optional<T>>)
   TypeLiteral.get(Types.newParameterizedType(Optional.class, type.getType()));
}

代码示例来源:origin: com.google.inject/guice

static <T> TypeLiteral<?> javaOptionalOf(TypeLiteral<T> type) {
 checkState(JAVA_OPTIONAL_CLASS != null, "java.util.Optional not found");
 return TypeLiteral.get(Types.newParameterizedType(JAVA_OPTIONAL_CLASS, type.getType()));
}

代码示例来源:origin: com.google.inject/guice

@SuppressWarnings("unchecked")
static <T> TypeLiteral<Collection<javax.inject.Provider<T>>> collectionOfJavaxProvidersOf(
  TypeLiteral<T> elementType) {
 Type providerType =
   Types.newParameterizedType(javax.inject.Provider.class, elementType.getType());
 Type type = Types.collectionOf(providerType);
 return (TypeLiteral<Collection<javax.inject.Provider<T>>>) TypeLiteral.get(type);
}

代码示例来源:origin: apache/incubator-druid

@SuppressWarnings("unchecked")
public static <T> void bindInstance(
  Binder binder,
  Key<T> bindKey,
  T instance
)
{
 binder.bind(bindKey).toInstance(instance);
 final ParameterizedType supType = Types.newParameterizedType(Supplier.class, bindKey.getTypeLiteral().getType());
 final Key supplierKey;
 if (bindKey.getAnnotationType() != null) {
  supplierKey = Key.get(supType, bindKey.getAnnotationType());
 } else if (bindKey.getAnnotation() != null) {
  supplierKey = Key.get(supType, bindKey.getAnnotation());
 } else {
  supplierKey = Key.get(supType);
 }
 binder.bind(supplierKey).toInstance(Suppliers.ofInstance(instance));
}

代码示例来源:origin: com.google.inject/guice

@SuppressWarnings("unchecked")
static <K, V> TypeLiteral<Map<K, javax.inject.Provider<V>>> mapOfJavaxProviderOf(
  TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
 return (TypeLiteral<Map<K, javax.inject.Provider<V>>>)
   TypeLiteral.get(
     Types.mapOf(
       keyType.getType(),
       newParameterizedType(javax.inject.Provider.class, valueType.getType())));
}

相关文章