package java.lang;/** * The {@code Void} class is an uninstantiable placeholder class to hold a * reference to the {@code Class} object representing the Java keyword * void. * * @author unascribed * @since JDK1.1 */public finalclass Void { /** * The {@code Class} object representing the pseudo-type corresponding to * the keyword {@code void}. */ @SuppressWarnings("unchecked") public static final ClassTYPE = (Class ) Class.getPrimitiveClass("void"); /* * The Void class cannot be instantiated. */ private Void() {}}
Class clazz = Class.forName("jdk.number.integer.Test01"); Method method = clazz.getMethod("testMethod", null); Class clazzRT = method.getReturnType(); System.out.println(clazzRT == Void.TYPE);
返回值是Void,这是一个占位符不能被实例化 ,大多数用来判断方法的返回值是不是空的