, "+" I = % d \ n ", str, I);} private void callInstanceMethod (String str, int I) {System. out. format ("ClassMethod: callInstanceMethod called! --> Str = % s, "+" I = % d \ n ", str, I );}}Header file generated by AccessMethod. class:
/* DO NOT EDIT THIS FILE - it is machine generated */#include Implementation of the function prototype in the local code object:
// AccessMethod. c # include "inline"/** Class: com_study_jnilearn_AccessMethod * Method: callJavaStaticMethod * Signature: () V */J
, it is much simpler to print out the classname in order. The only problem is the typographical problem. First, let's get the code I wrote and explain it further:
Public class reflectanimal {public static void main (string [] ARGs) throws classnotfoundexception {class clazz = Class. forname ("it. cast. heima. animals2 "); printall (clazz);} // print the values of all fields, excluding the Private Static voi
file classes. Although you can reach the directory hierarchy, you can call classes. class. getresource ("") returns NULL. because the directory structure of the file is different from the folder itself.
Obtain the path of a class: Obtain the location where the class itself stores files in the system, and then locate the classpath according to the package level:
Package
Com. wbtask; ImportJava. Io. file;ImportJava.net. url; Public Class Urlutil { /** * Obtain the file of the curr
The Code is as follows:[Java]Package xiaogang. enif. utils;/*** The Class LogUtils for log printing, which help us* Easy to trace our codes or logics in the project.** @ Author zhao xiaogang* @ Time 2011.4.12*/Public class LogUtils {Private final static int VERBOSE = 0;Private final static int DEBUG = 1;Private final static int INFO = 2;Private final static int WARN = 3;Private final static int ERROR = 4;Private final static int DEFAULT_LEVEL =-1;Private int level;Private final String
. Reflection benefits
Reflection technology greatly improves program scalability
3. the Java reflection mechanism provides the following functions:
Determine the class to which any object belongs at runtime;
Construct any class object at runtime;
Judge the member variables and methods of any class at runtime;
Call methods of any object at runtime;
Generate dynamic proxy
Ii. Obtain the Class Object
public static void getClassObject_3() throws ClassNotFoundException {String className
: A constructor that describes a class
For public domains (including superclass members): GetFields GetMethods GetConstructors
For other domains (including private and protected members, excluding superclass members): Gettdeclaredfields gettdeclaredmethods gettdeclaredconstructors
The following describes the use of Java reflection, where the person class and the test complete code are at the end of this article. Load Class
3 Ways to load classes class
have datasource, creating a Connectionsource can take the following code:ConnectionSource source = ConnectionSourceHelper.getSingle(datasource);If it is a master-slave datasource:ConnectionSource source = ConnectionSourceHelper.getMasterSlave(master,slaves)2. Query API(1) Simple query (automatically generate SQL)public T Unique (Class clazz,object PK) query based on primary key, throw exception if not foundPublic T single (Class
monitor as an example to explain1, Class class:public class Clazz implements java.io.Serializable {//fieldsprivate Integer classid;private String classname;private Mon Itor monitor;//constructors/** default constructor */public Clazz () {}/** Full constructor *///property Accessorspublic Integer GetClassID () {return this.classid;} Public Clazz (String className
1. First define an interface in the DaO layer:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Public
Interface
Basedao {
T
>
Void
Add (t object );
T
>
Void
Delete (class clazz, serializable ID );
T
>
Void
Update (T clazz );
T
>
T get (Class
T
>
Clazz, se
from the pool5. Provision of the return method, the consequences of not return very serious6. Control the request wait time method, after a certain event has not obtained an object instance, return a null pointer
Import Java.util.Stack; @SuppressWarnings ("Unchecked") public class Objectpool {public Objectpool () {} private Poolparam Poolparam
;
public void Setpoolparam (Poolparam poolparam) {this.poolparam = Poolparam;
}//Current total object number private int currentnum = 0
compatibility reasons.
For the above reasons, a new concept has been introduced. The virtual extension method, also known as the Defender method, can now be added to the interface so that it can provide a default implementation of the declared behavior.
Simply put, the Java interface can now implement the method. The advantage of the default method is that you can add new default methods to the interface without breaking the implementation of the interface.
In my opinion, this is not the kin
to see * if your tag should be logged. You can change the default level by setting a system property: * 'setprop log.tag.The native Implementation of isLoggable is in frameworks/base/core/jni/android_util_Log.cpp:
Static JNINativeMethod gMethods [] = {/* name, signature, funcPtr */{"isLoggable", "(Ljava/lang/String; I) Z", (void *) android_util_Log_isLoggable}, {"println_native", "(IILjava/lang/String; Ljava/lang/String;) I", (void *) android_util_Log_println_native },}; static jb
Java passes the data to the C example:public class JNI {static{System.loadlibrary ("PassData");}Pass two variables of type int to C let C add a second to returnpublic native int Add (int x, int y);Pass arguments of type string to C and return toPublic native string Sayhelloinc (string s);Passing an array of type int to CPublic native int[] Arrelementsincrease (int[] intarray);}Written in the C language:#include #include #include #define LOG_TAG "System.out"#define LOGD (...) __android_log_print
A class has several components, such as: member variables, methods, construction methods, and so on.Reflection is the loading of classes, and the dissection of the various components of the classReflection: The load class obtains the direct code of the Class (3 methods)1.Class clazz =class.forname ("Cn.itcast.reflect.person");2.Class clazz1=new person (). GetClass ();3.Class Clazz2=person.class;Reflection constructors, creating objects of classesConst
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.