您的位置:首页 > 编程语言 > Java开发

java.lang.Class.getComponentType()方法

2016-06-11 20:16 483 查看


描述

java.lang.Class.getComponentType() 方法返回类的组件类型的数组。如果这个类并不代表一个数组类,此方法返回null。


声明

以下是声明java.lang.Class.getComponentType()方法
public Class<?> getComponentType()


参数

NA


返回值

此方法返回的类,这个类,如果这个类是一个数组组件类型。


异常

NA


实例

下面的例子说明了如何使用java.lang.Class.getComponentType()方法。
package com.yiibai;

import java.lang.*;

public class ClassDemo {

public static void main(String[] args) {

String[] arr = new String[] {"admin"};

// returns the Class representing the component type
Class arrClass = arr.getClass();
Class componentType = arrClass.getComponentType();
if (componentType != null) {
System.out.println("ComponentType = " + componentType.getName());
}
else {
System.out.println("ComponentType is null");
}
}
}


让我们来编译和运行上面的程序,这将产生以下结果:

ComponentType = java.lang.String

转载:http://www.yiibai.com/javalang/class_getcomponenttype.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java sdk