Clazz

public boolean isPrimitive()

Determines if the specified Class object represents a primitive type.

There are nine predefined Class objects to represent the eight primitive types and void.  These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.

These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.

  • Returns: true if and only if this class represents a primitive type

判断是否是原始类型。

Java的原始类型有八种:int, double, float, long, short, boolean, byte, char, void.

只有以这几中类型调用时,返回true.

示例代码:

package learn.classes;

import org.junit.Test;
public class Clazz {
    @Test
    public void isPrimitive() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException{
        Class[] primitiveClasses={int.class,long.class,float.class,long.class,
                boolean.class, byte.class, char.class, short.class,double.class};
        Class[] wrappedClasses={Integer.class,String.class};
        for(Class clazz:primitiveClasses){
            System.out.println(clazz.getSimpleName()+" is isPrimitive: "+clazz.isPrimitive());
        }
        System.out.println("*****************************");
        for(Class clazz:wrappedClasses){
            System.out.println(clazz.getSimpleName()+" is isPrimitive: "+clazz.isPrimitive());
        }
    }
    /*
    int is isPrimitive: true
    long is isPrimitive: true
    float is isPrimitive: true
    long is isPrimitive: true
    boolean is isPrimitive: true
    byte is isPrimitive: true
    char is isPrimitive: true
    short is isPrimitive: true
    double is isPrimitive: true
    *****************************
    Integer is isPrimitive: false
    String is isPrimitive: false
    */

}




转载于:https://my.oschina.net/u/2525078/blog/658244

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值