本文整理汇总了Java中net.bytebuddy.description.type.TypeDescription.Generic.getUpperBounds方法的典型用法代码示例。如果您正苦于以下问题:Java Generic.getUpperBounds方法的具体用法?Java Generic.getUpperBounds怎么用?Java Generic.getUpperBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.bytebuddy.description.type.TypeDescription.Generic
的用法示例。
在下文中一共展示了Generic.getUpperBounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendTypeParameter
import net.bytebuddy.description.type.TypeDescription.Generic; //导入方法依赖的package包/类
/**
* Append a type parameter
*
* @param typeParameter Type parameters to append
* @param output Output to append to
* @param <A> Type of output
* @return Supplied output to append to
*/
public <A extends Appendable> A appendTypeParameter(Generic typeParameter, A output) {
try {
output.append(typeParameter.getSymbol());
TypeList.Generic upperBounds = typeParameter.getUpperBounds();
if (upperBounds.size() == 0) {
throw new IllegalArgumentException(
String.format("Type parameter '%s' must have upper bounds", typeParameter));
}
if (upperBounds.get(0).isInterface()) {
output.append(':');
}
for (Generic upperBound : upperBounds) {
appendClassOrInterfaceBound(upperBound, output);
}
return output;
}
catch (Exception e) {
throw new RuntimeException(String.format("Could not write type parameter %s", typeParameter));
}
}
示例2: appendTypeArgument
import net.bytebuddy.description.type.TypeDescription.Generic; //导入方法依赖的package包/类
/**
* Append a type Argument
*
* @param typeArgument Type argument to append
* @param output Output to append to
* @param <A> Type of output
* @return Supplied output to append to
*/
public <A extends Appendable> A appendTypeArgument(Generic typeArgument, A output) {
try {
if (typeArgument.getSort() == Sort.WILDCARD) {
TypeList.Generic lowerBounds = typeArgument.getLowerBounds();
TypeList.Generic upperBounds = typeArgument.getUpperBounds();
if (lowerBounds.size() > 0) {
if (upperBounds.size() != 1 || !upperBounds.get(0).represents(Object.class)) {
throw new IllegalArgumentException(String.format(
"Lower bounded type argument '%s' must have Object as upper bound", typeArgument));
}
output.append('-');
appendReferenceTypeSignature(typeArgument.getLowerBounds().get(0), Nullness.UNDEFINED, output);
}
else if (upperBounds.size() > 0) {
if (upperBounds.size() > 1) {
throw new IllegalArgumentException(
String.format("Upper bounded type argument '%s' cannot have more than one upper bound",
typeArgument));
}
if (upperBounds.get(0).represents(Object.class)) {
output.append('*');
}
else {
output.append('+');
appendReferenceTypeSignature(upperBounds.get(0), Nullness.UNDEFINED, output);
}
}
}
else {
appendReferenceTypeSignature(typeArgument, Nullness.UNDEFINED, output);
}
return output;
}
catch (Exception e) {
throw new RuntimeException(String.format("Could not write type argument %s", typeArgument));
}
}