Session6 module8 9 annotations reflection

33 606 0
Session6 module8 9 annotations reflection

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

m mới bắt đầu học java nên chưa có kinh nghiệm gì, nên mong các tiền bối đi trước cho em vài lời khuyên. trước đây em có học qua về c++ với C và php nhưng không thực sự giỏi cái nào. hiện nay em đang có bài tập lớn về java,mà em thì không có kinh nghiệm gì về nó nên muốn chọn mảng nào dễ hơn để có thể dễ bắt đầu, nếu các anh chị nào đã học qua thì cho em 1 vài lời khuyên với.em xin cám ơn các anh chị trước.

    •  ! Module 8 – Annotations ""#$%&'()*+(,-")(, +./ • )012 • (3.232 • *12 • "32 • "3"4 516 • .7411provide additional information about existing pieces of data$ • 1413344$*1891 83343.8.331139 3344$ • .32343737$"443 3.848$ • 1133443323..8 .313.23431 3$  • annotation4.81334431$ 3317218$ • Annotation typ17$*1.81334431 43$ • *104.74: // Definition of an Annotation type public @interface TestAnnotation { String value; } // Usage of Annotation @TestAnnotation (value="name") public void display() {} Uses of Annotations • 14.32: – Information for the compiler;..8143 333333$ – Compiler-time and deployment-time processing;23 32343<=>7<231$ – Runtime processing;43..04 34$ • .334?32< 7<41<133344$ (+(+-@* DO DO if the metadata changes the design of the class. if the metadata changes the design of code dealing with class. if the metadata changes the design of the class. if the metadata changes the design of code dealing with class. DON’T DON’T • 2883 .3.. 33 . • 51873 384.$ • 2883 .3.. 33 . • 51873 384.$ "32 • 3A3 – "241 – B3<1@TestAnno •  – "2<4343A3$ – ".33:C3 – )04:@TestAnno(“Testing”) • D – "2444.3$ – )144.333.8C3 – @TestAnno(owner=“Stephen”, value=“class scope”) E • F(3 • F+33 • F353 • F*3 • F • F13 [...]... the members of the annotations is of no importance • The decleration of annotation type should be in the same package as the class using the Annotation Module8 - Summary ACCP I7.1 - A GUIDE TO ADVANCED JAVA Module 9 Reflection API Module Obectives 23 Introduction to Reflection API • Reflection is the ability of classes, objects and interfaces to find information about itself • The reflection API are... static void displayArray(Object source){ System.out.println(Array.get(source, 0)); Array.set(source, 0, 100); System.out.println(Array.get(source, 0)); } } Module 9: Summary • In this module, Reflection API, you learnt about: – Introduction to Reflection API – Analysing classes – Working with objects – Manipulating Arrays ... types as well as objects Array and Reflection • The Array class – – Is used to dynamically create and access arrays at runtime Class.isArray() method is used to check whether a particular object is an array • Arrays can be created during runtime by invoking Array.newInstance() method – The newInstance() method specifies a base type and length the Example package reflectiondemo; import java.lang.reflect.Array;... Reflection is the ability of classes, objects and interfaces to find information about itself • The reflection API are used to write development tools, such as debuggers, class browsers and GUI builder • Reflection API is used for the following purposes: – – – Analyzing classes Controlling objects Controlling with arrays 24 Analyzing classes • Retrieving class name: – If an instance of the class is available,... RetentionPolicy.RUNTIME EXAMPLE @Retention(RetentionPolicy.SOURCE) @interface Test_Retention { String v1(); } class RetentionTest { @Test_Retention(v1="Hello") public void thu() {System.out.println("Test annotations" );} } class RetentionAnno {public static void main(String args[]) { new RetentionTest().thu(); } } Custom Annotation for Class • • To create an annotation type for classes, the "@" symbol followed.. .Annotations Used by the Compiler // Javadoc comment follows /** * @deprecated * explanation of why it was deprecated */ @Deprecated static void deprecatedMethod() { } } // mark method as a superclass method . data$ • 1413344$*18 9 1 83343.8.33113 9  3344$ • .32343737$"443 3.848$ • 1133443323..8 .313.23431 3$  • annotation4.81334431$ 3317218$ • Annotation.     •  ! Module 8 – Annotations ""#$%&'()*+(,-")(, +./ • )012 • (3.232 • *12 • "32 • "3"4 516 • .7411provide. } // Usage of Annotation @TestAnnotation (value="name") public void display() {} Uses of Annotations • 14.32: – Information for the compiler;..8143 333333$ – Compiler-time

Ngày đăng: 22/11/2014, 16:39

Mục lục

    DO and DON’T

    Annotations Used by the Compiler

    Custom Annotation for Class

    Custom Annotation for Method

    Introduction to Reflection API

    Example for Analyzing classes

    Example for Analyzing classes

Tài liệu cùng người dùng

  • Đang cập nhật ...