当前位置: 首页>>代码示例>>Java>>正文


Java Generic.getUpperBounds方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:jochenseeber,项目名称:gradle-project-config,代码行数:34,代码来源:MethodSignatureWriter.java

示例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));
    }
}
 
开发者ID:jochenseeber,项目名称:gradle-project-config,代码行数:50,代码来源:MethodSignatureWriter.java


注:本文中的net.bytebuddy.description.type.TypeDescription.Generic.getUpperBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。