当前位置: 首页 > news >正文

java:Class的isPrimitive方法使用

java:Class的isPrimitive方法使用

1 前言

java中Class类的isPrimitive方法,用于检查类型是否为基本类型。java虚拟机创建了int、byte、short、long、float、double、boolean、char这8种基础信息,以及void,一共9种。为这9种类型时,isPrimitive方法将返回true,反之返回false。

参考java api文档说明:

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
Since:
JDK1.1
See Also:
Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE

2 使用

public static void isPrimitive(){System.out.println(Boolean.TRUE.getClass().isPrimitive());System.out.println(TestAsync.class.isPrimitive());Class<?> a = new Integer(1).getClass();System.out.println(a.isPrimitive());System.out.println("*******************");System.out.println(int.class.isPrimitive());System.out.println(byte.class.isPrimitive());System.out.println(short.class.isPrimitive());System.out.println(long.class.isPrimitive());System.out.println(float.class.isPrimitive());System.out.println(double.class.isPrimitive());System.out.println(boolean.class.isPrimitive());System.out.println(char.class.isPrimitive());System.out.println(void.class.isPrimitive());
}

执行结果:

false
false
false
*******************
true
true
true
true
true
true
true
true
true
http://www.lryc.cn/news/24653.html

相关文章:

  • TCP 握手过程 三次 四次
  • windows 下 安裝mysql 5.7.41 (64位) 超简单方式
  • 二叉树——二叉树的最近公共祖先
  • 数据结构与算法基础-学习-14-线性表之串
  • Mac 快捷键
  • 【微服务】-微服务环境搭建
  • IGKBoard(imx6ull)-ADC编程MQ-2烟雾传感器采样
  • 前端二面vue面试题总结
  • 时间API在更新,传奇已经谢幕,但技术永远不死
  • SQL调优指南笔记22:Gathering Diagnostic Data with SQL Test Case Builder
  • 从0开始学python -43
  • Kafka基本原理
  • css3的重点内容
  • 《Roller: Fast and Efficient Tensor Compilation for Deep Learning》
  • 顺丰同城测试开发一面 49min答案,全文7000字,面试总结都在这里了
  • docker启动容器服务之后访问失败
  • GraalVM-云原生时代的JVM(Java)
  • 如何外网登录访问瑞友天翼应用虚拟化系统?——快解析内网端口映射方案
  • 蓝海彤翔执行副总裁张加廷接受【联播苏州】独家专访
  • iOS Airplay Screen Mirroring 同屏技术详解
  • 更新 Python 100道基础入门检测练习题【下篇】(附答案)
  • [RDMA-高级计算机网络report] Congestion Control for Large-Scale RDMA Departments
  • ROS2功能包Hello world(python)
  • 数学建模竞赛的一些心得体会
  • 什么是自动化测试?自动化测试现状怎么样?
  • CHAPTER 2 Web HA集群部署 - Heartbeat
  • 蓝桥杯每日一题:不同路径数(dfs深度优先)
  • NCRE计算机等级考试Python真题(十)
  • 【蓝桥杯嵌入式】点亮LED灯,流水灯的原理图解析与代码实现——STM32
  • RK3288-android8-es7210-阵列麦克风