[Groovy123] basic concepts and design ideas in Groovy

Groovy:

http://www.groovy-lang.org/

https://blog.csdn.net/weixin_33862993/article/details/86258972

 

https://www.cnblogs.com/zqlxtt/p/5741240.html

 

Gradle (Groovy Example):

https://www.cnblogs.com/zqlxtt/tag/gradle/

https://www.jianshu.com/p/20f6695a9bd5

 

Other concepts:

reflection

https://blog.csdn.net/jin_luo/article/details/79763938

https://segmentfault.com/a/1190000016105692

https://www.cnblogs.com/dabai123/p/11595178.html

https://www.cnblogs.com/zuzizai/p/7594368.html

1.1. Hardcoded (normal mode)

RTTI is assumed at compile time, already know all the types of information . When coding, you can directly use specific types of information, which is the most common type of usage. At compile time, the compiler by the vessel, the generic integrity assurance type system; at run time, by the type of conversion operation to ensure this.

1.2. Reflect (reflection method)

Reflect allows us to obtain and use type information at run time , it is mainly used in the compilation stage can not get all types of information scene, such as various types of frames.

Reflection, may, at run-time, hard coded dynamic Java implementation of all functions performed by a special set of API (such as object creation, method call, etc.). Compared to hard-coded, Java reflection API is much more complex, but it gives us greater flexibility.

Examples of Class class object (four methods):

1) provided: if known concrete classes, class by class attribute acquisition, the method 
                    is most reliable, highest application performance
       Example: Class = clazz String. Class ;
2) provided: known instance of a class, calling the examples of getClass () method is eligible
                    to take class object
       instance: class clazz = "www.atguigu.com." getClass () ;
. 3) provided: a fully qualified class name of the class is known, and the class in the class path, by
       class class static method the forName () Gets, may be thrown ClassNotFoundException
       example: class class = clazz. the forName ( "java.lang.String");
. 4) otherwise (not required)
ClassLoader this.getClass = Cl (). getClassLoader () ;
. = Cl class clazz4 the loadClass ( "full class name of the class");

/** RefelctDemo */

public  class ReflectDemo {
     // Get a total of three ways constructor (frame programmer) 
    @Test
     public  void test1 () throws Exception, Exception {
        Class clazz  =  Student.class;
        Constructor c = clazz.getConstructor(null);
        Student s = (Student)c.newInstance(null);
        System.out.println(s);
        
    }
    @Test
    public void test2() throws Exception, Exception{
        Class clazz  =  Student.class;
        Object object = clazz.newInstance();
        System.out.println(object.getClass().getName());
        
    }
    @Test
    public void test3() throws Exception, Exception{
        Class c =Class.forName("Reflect.Student");
        Student s =(Student) c.newInstance();
        System.out.println(s);
        
    }
    // Get has parameters configured 
    @Test
     public  void Test4 () throws Exception, Exception {
    Clazz class . = Student class ;
     // Get constructor 
    the Constructor clazz.getConstructor C = (String. Class );
    Student s =(Student)c.newInstance("赵日天");
    System.out.println(s.getName());
    }
    // Get private constructor method 
    @Test
     public  void Test5 () throws Exception, Exception {
        Class clazz =Student.class;
        Constructor an = clazz.getDeclaredConstructor(Date.class);
        //暴力反射
        an.setAccessible(true);
        Student s =(Student)an.newInstance(new Date());
        System.out.println(s.getData());
                
    }
}

Dynamic Proxy

https://www.jianshu.com/p/7b5af86a9984

Java dynamic proxy further than the agency, because it can dynamically create a proxy and dynamic handling calls to the proxy approach. In the dynamic proxy all calls made will be redirected to the processor on a single call.

 

JDK dynamic proxy implementation

Proxy.java

 

InvocationHandler.java

Closure

Guess you like

Origin www.cnblogs.com/cathygx/p/12049710.html