TAILIEUCHUNG - Thinking in Java 4th Edition phần 6

Trong trường hợp đó, để thực hiện Bộ sưu tập bạn sẽ phải thực hiện tất cả các phương pháp trong Bài tập 9: (5) Bắt đầu với , tạo ra một chương trình với đầy đủ chức năng của . | Simpo PDF Merge and Split Unregistered Version - http . . Output Woof Sitting Click Clank Mime cannot speak Pretending to sit Here the classes are completely disjoint and have no base classes other than Object or interfaces in common. Through reflection is able to dynamically establish whether the desired methods are available and call them. It is even able to deal with the fact that Mime only has one of the necessary methods and partially fulfills its goal. Applying a method to a sequence Reflection provides some interesting possibilities but it relegates all the type checking to run time and is thus undesirable in many situations. If you can achieve compile-time type checking that s usually more desirable. But is it possible to have compile-time type checking and latent typing Let s look at an example that explores the problem. Suppose you want to create an apply method that will apply any method to every object in a sequence. This is a situation where interfaces don t seem to fit. You want to apply any method to a collection of objects and interfaces constrain you too much to describe any method. How do you do this in Java Initially we can solve the problem with reflection which turns out to be fairly elegant because of Java SE5 varargs generics main ApplyTest import . import . import static . public class Apply public static T S extends Iterable extends T void apply S seq Method f Object. args try for T t seq t args catch Exception e Failures are programmer errors throw new RuntimeException e class Shape public void rotate print this rotate public void resize int newSize print this resize newSize class Square extends Shape class FilledList T extends ArrayList T Generics 519 Simpo PDF Merge and Split Unregistered Version - http public FilledList Class extends T type int size try for int i 0 i size i Assumes default constructor .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.