java.lang.Boolean学习

基础类:

package tjava.testlang; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class BasicClassTest { static String className = null; public static void showClassInfo(String className) throws ClassNotFoundException { if(className == null || className.isEmpty()) { logPrintln("No class to test."); return; } Class<?> cls = Class.forName(className); logPrintln(" package name : " + cls.getPackage().getName()); logPrintln(" class name : " + cls.getName()); logPrintln("super class name : " + cls.getSuperclass().getName()); logPrintln(" include method : "); for(Method method:cls.getMethods()) { logPrintln(" " + method.getName()); } logPrintln(" include field : "); for(Field field:cls.getFields()) { logPrintln(" " + field.getName()); } logPrintln("include Constructor : "); for(Constructor<?> ctr:cls.getConstructors()) { logPrint(" " + ctr.getName() + "("); for(Class<?> p:ctr.getParameterTypes()) { logPrint(" " + p.getName()); } logPrintln(" )"); } } public static void logPrintln(String s) { System.out.println(s); } public static void logPrint(String s) { System.out.print(s); } }

Boolean类演示代码:

 

package tjava.testlang; import java.lang.Boolean; public class TestBoolean extends BasicClassTest { static String className = "java.lang.Boolean"; public static void test() throws ClassNotFoundException { logPrintln("Test Show:"); logPrintln(" Boolean(/"false/") = " + new Boolean("false")); logPrintln(" Boolean(/"true/") = " + new Boolean("true")); logPrintln("Boolean.parseBoolean(null) = " + Boolean.parseBoolean(null)); logPrintln(" Boolean.valueOf(null) = " + Boolean.valueOf(null)); logPrintln(" Boolean.TYPE = " + Boolean.TYPE); } public static void showClassInfo() throws ClassNotFoundException { BasicClassTest.showClassInfo(className); } }  

验证的类:

package tjava.testlang; public class TestMain { public static void main(String[] args) { // TODO Auto-generated method stub try { TestBoolean.showClassInfo(); TestBoolean.test(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }  

 

 

 

结果:

 package name : java.lang
      class name : java.lang.Boolean
super class name : java.lang.Object
  include method :
                   equals
                   toString
                   toString
                   hashCode
                   compareTo
                   compareTo
                   getBoolean
                   booleanValue
                   valueOf
                   valueOf
                   parseBoolean
                   wait
                   wait
                   wait
                   getClass
                   notify
                   notifyAll
   include field :
                   TRUE
                   FALSE
                   TYPE
include Constructor :
                   java.lang.Boolean( java.lang.String )
                   java.lang.Boolean( boolean )
Test Show:
          Boolean("false") = false
           Boolean("true") = true
Boolean.parseBoolean(null) = false
     Boolean.valueOf(null) = false
              Boolean.TYPE = boolean 

你可能感兴趣的:(String,null,Class,import,include,Constructor)