zoukankan      html  css  js  c++  java
  • java.lang.Class.isPrimitive()用法解析

    一、概述:

    此方法主要用来判断Class是否为原始类型(boolean、char、byte、short、int、long、float、double)。

    二、格式:

    Class.isPrimitive(),原始类型下返回true

    三、示例:

    public static void main(String[] args){
    
        Class stringClass=String.class;
        System.out.println("String is primitive type:"+stringClass.isPrimitive());
    
        Class booleanClass=Boolean.class;
        System.out.println("Boolean is primitive type:"+booleanClass.isPrimitive());
    
        Class booleanType=boolean.class;
        System.out.println("boolean is primitive type:"+booleanType.isPrimitive());
    
        Class byteType=byte.class;
        System.out.println("byte is primitive type:"+byteType.isPrimitive());
    
        Class charType=char.class;
        System.out.println("char is primitive type:"+charType.isPrimitive());
    
        Class shortType=short.class;
        System.out.println("short is primitive type:"+shortType.isPrimitive());
    
        Class intType=int.class;
        System.out.println("int is primitive type:"+intType.isPrimitive());
    
        Class longType=long.class;
        System.out.println("long is primitive type:"+longType.isPrimitive());
    
        Class floatType=float.class;
        System.out.println("float is primitive type:"+floatType.isPrimitive());
    
        Class doubleType=double.class;
        System.out.println("double is primitive type:"+doubleType.isPrimitive());
    }
    

    结果输出:

    String is primitive type:false
    Boolean is primitive type:false
    boolean is primitive type:true
    byte is primitive type:true
    char is primitive type:true
    short is primitive type:true
    int is primitive type:true
    long is primitive type:true
    float is primitive type:true
    double is primitive type:true
    
      注:文章中难免有不足之处,欢迎评论、互动、指正。

    作者: i-nine
    原创不易,本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    字符串函数---atof()函数具体解释及实现(完整版)
    curl的简单使用
    [7] 算法之路
    springMVC3.0(文件上传,@RequestMapping加參数,@SessionAttributes,@ModelAttribute,转发,重定向,数值获取,传參,ajax,拦截器)
    hdu 1754 I Hate It 线段树 点改动
    经典的7种排序算法 原理C++实现
    自己定义View实现水平滚动控件
    centos编译ffmpeg x264
    工作脚本处理文本
    A*寻路算法
  • 原文地址:https://www.cnblogs.com/ninth/p/6164471.html
Copyright © 2011-2022 走看看