Đang chuẩn bị liên kết để tải về tài liệu:
Programming Groovy dynamic productivity for the java developer phần 8

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

chặn cuộc gọi để làm việc làm việc . chặn cuộc gọi cho playTennis methodMissing gọi cho playTennis chơi Tennis . chặn cuộc gọi cho playTennis chơi Tennis .Phương pháp tổng hợp Sử dụng ExpandoMetaClass cuộc gọi trong tương lai sẽ sử dụng impl trở lại | Method Synthesis Using methodmissing 218 if method return method.invoke this args else return metaClass.invokeMethod this name args def methodMissing String name args System.out.println methodMissing called for name def methodInList plays.find it name.split play 1 if methodInList def impl Object vargs - return playing name.split play 1 . Person.metaClass. name impl future calls will use this return impl args else throw new MissingMethodException name Person.class args jack new Person println jack.work println jack.playTennis println jack.playTennis The output from the previous code is as follows intercepting call for work working. intercepting call for playTennis methodMissing called for playTennis playing Tennis. intercepting call for playTennis playing Tennis. Method Synthesis Using ExpandoMetaClass 219 14.5 Method Synthesis Using ExpandoMetaClass In Section 14.4 Method Synthesis Using methodMissing on page 214 you saw how to synthesize methods. If you don t have the privilege to edit the class source file or if the class is not a POGO that approach will not work. You can synthesize methods using the ExpandoMetaClass in these cases. You already saw how to interact with MetaClass in Section 13.2 Intercepting Methods Using MetaClass on page 197. Instead of providing an interceptor for a domain method you implement the methodMissing method on it. Let s take the Person class and the boring jack from Section 14.4 Method Synthesis Using methodMissing on page 214 but instead we ll use ExpandoMetaClass as shown here Download InjectionAndSynthesisWithMOP MethodSynthesisUsingEMC.groovy ExpandoMetaClass.enableGlobally class Person def work working. Person.metaClass.methodMissing String name args - def plays Tennis VolleyBall BasketBall System.out.println methodMissing called for name def methodInList plays.find it name.split play 1 if methodInList def impl Object vargs - return playing name.split play 1 . Person.metaClass. name impl future calls will use this return impl .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.