1, first Java in each class object has a class byte code, all belong to class.
Java's 9 basic data types: int, short, long, float, double, char, Byte, Boolen, and void. They correspond to classes that are not the same as their corresponding class objects, such as Int.class==integer.class returns false, but the base data type of the Integer wrapper is int, so Integer.type==int.class returns True. Determines whether a class is the base data type calss.isprimitive (). An array of base data types is not a base type: that is, Int[].class.isprimitive returns False,int[].class.isarray true.
An array of basic data types must have the same number of dimensions as the type of byte code that is obtained:
2, Java reflection, the first reflection can get the class by the class name bytecode, and then get the various properties, methods, construction methods and so on all of the class. Here's how to get the class object, and the methods and properties can of course manipulate the object.
public static void MyTest (String cl) {//requires the user to enter the full path of the class try { Class Cla=class.forname (CL);//classes are loaded according to the full path of the class, returning the Class object
Object O=cla.newinstance ();//Get CLA's Like, if there is a constructor that has parameters, it gets its constructor and then creates. The premise is to have a certain understanding of the class to use reflection method[] method=cla.getdeclaredmethods ();//Use the resulting class object's self-audit, return the method object set for (M Ethod me:method) {//Traverse the collection System.out.println (Me.tostring ()) of such methods;//Print method information} System.out.println ("********"); Field[] Field=cla.getdeclaredfields ()///Use the resulting class object's self-audit, return the Property object collection for (field Me:field) {//Iterate over the collection of the class properties System.out.println (Me.tostring ());//print attribute Information}} catch (ClassNotFoundException e) {E.pri Ntstacktrace (); } }
3, the reflection effect: The simplest use I have a lot of objects, each of which is different. I need to stitch them up into the standard drawing string I want no matter what the difference between the object constructs I directly reflect the property name and property values to do what I want to do a method to fit all classes do not reflect you want to write a method for each class Because the attribute names in each class don't know the property names, they can't be written, but with reflection you don't need to know a property name. For example: There are many tables in the database, each table has its own properties, and the number of attributes are not the same, and no table has the corresponding additions and deletions to check the operation, if not reflected you must each table write a method of adding and deleting, trouble-cutting code redundancy large. The use of reflection, the parameters of the class passed in (and the same method as above), so that all the properties can be the corresponding operation, you only need to write a delete and change the search.
Java class, base type, reflection