本文整理汇总了Java中com.google.common.reflect.TypeToken.getType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.getType方法的具体用法?Java TypeToken.getType怎么用?Java TypeToken.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.reflect.TypeToken
的用法示例。
在下文中一共展示了TypeToken.getType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testResolveGenericMessage
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Test
public void testResolveGenericMessage() throws Exception {
final TypeToken<? extends Message> token = registry.resolve("ModelUpdate", Optional.of("Server"));
assertAssignableTo(new TypeToken<ModelUpdate<Server>>(){}, token);
final Type type = token.getType();
assertInstanceOf(ParameterizedType.class, type);
final ParameterizedType pType = (ParameterizedType) type;
assertEquals(ModelUpdate.class, pType.getRawType());
assertEquals(Server.class, pType.getActualTypeArguments()[0]);
}
示例2: BaseFieldKey
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private BaseFieldKey(String name, String columnName, boolean nullable, TypeToken<T> valueType,
FieldGeneratorType fieldGeneratorType, T defaultValue){
this.name = name;
this.columnName = columnName;
this.nullable = nullable;
this.valueType = valueType.getType();
this.fieldGeneratorType = fieldGeneratorType;
this.defaultValue = defaultValue;
}
示例3: convert
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Object convert(Object source, TypeToken<?> targetTypeToken) {
if (!canHandle(source, targetTypeToken)) {
throw new ConverterException(source, targetTypeToken.getRawType());
}
Integer period = null;
if (source instanceof Number) {
period = (Integer) numberToNumberConverter.convert(source, TypeToken.of(Integer.class));
} else if (source instanceof String) {
period = (Integer) stringToNumberConverter.convert(source, TypeToken.of(Integer.class));
}
Type targetType = targetTypeToken.getType();
if (targetType.equals(Seconds.class)) {
return Seconds.seconds(period);
} else if (targetType.equals(Minutes.class)) {
return Minutes.minutes(period);
} else if (targetType.equals(Hours.class)) {
return Hours.hours(period);
} else if (targetType.equals(Days.class)) {
return Days.days(period);
} else if (targetType.equals(Weeks.class)) {
return Weeks.weeks(period);
} else if (targetType.equals(Months.class)) {
return Months.months(period);
} else if (targetType.equals(Years.class)) {
return Years.years(period);
}
throw new ConverterException(source, targetTypeToken.getRawType());
}
示例4: GsonStorageHandler
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public GsonStorageHandler(String fileName, String fileExtension, File dataFolder, TypeToken<T> type) {
this(fileName, fileExtension, dataFolder, type.getType());
}