modifiers在JAVA中_Java Modifier.classModifiers方法代碼示例

import java.lang.reflect.Modifier; //導入方法依賴的package包/類

/**

* Returns a string describing this {@code Class}, including

* information about modifiers and type parameters.

*

* The string is formatted as a list of type modifiers, if any,

* followed by the kind of type (empty string for primitive types

* and {@code class}, {@code enum}, {@code interface}, or

* @{@code interface}, as appropriate), followed

* by the type's name, followed by an angle-bracketed

* comma-separated list of the type's type parameters, if any.

*

* A space is used to separate modifiers from one another and to

* separate any modifiers from the kind of type. The modifiers

* occur in canonical order. If there are no type parameters, the

* type parameter list is elided.

*

*

Note that since information about the runtime representation

* of a type is being generated, modifiers not present on the

* originating source code or illegal on the originating source

* code may be present.

*

* @return a string describing this {@code Class}, including

* information about modifiers and type parameters

*

* @since 1.8

*/

public String toGenericString() {

if (isPrimitive()) {

return toString();

} else {

StringBuilder sb = new StringBuilder();

// Class modifiers are a superset of interface modifiers

int modifiers = getModifiers() & Modifier.classModifiers();

if (modifiers != 0) {

sb.append(Modifier.toString(modifiers));

sb.append(' ');

}

if (isAnnotation()) {

sb.append('@');

}

if (isInterface()) { // Note: all annotation types are interfaces

sb.append("interface");

} else {

if (isEnum())

sb.append("enum");

else

sb.append("class");

}

sb.append(' ');

sb.append(getName());

TypeVariable>[] typeparms = getTypeParameters();

if (typeparms.length > 0) {

boolean first = true;

sb.append('

for(TypeVariable> typeparm: typeparms) {

if (!first)

sb.append(',');

sb.append(typeparm.getTypeName());

first = false;

}

sb.append('>');

}

return sb.toString();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值