Programming Groovy dynamic productivity for the java developer phần 8

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 this args else return this name args def methodMissing String name args methodMissing called for name def methodInList it play 1 if methodInList def impl Object vargs - return playing play 1 . . name impl future calls will use this return impl args else throw new MissingMethodException name args jack new Person println println println 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 Method Synthesis Using ExpandoMetaClass In Section 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 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 Method Synthesis Using methodMissing on page 214 but instead we ll use ExpandoMetaClass as shown here Download InjectionAndSynthesisWithMOP class Person def work working. String name args - def plays Tennis VolleyBall BasketBall methodMissing called for name def methodInList it play 1 if methodInList def impl Object vargs - return playing play 1 . . name impl future calls will use this return impl .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.