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

Bộ sưu tập, bạn cũng thực hiện iterator (), và chỉ thực hiện iterator () một mình đòi hỏi nỗ lực chỉ hơi ít hơn so với kế thừa từ AbstractCoUection. Tuy nhiên, nếu lớp học của bạn đã được thừa kế từ một lớp khác, sau đó bạn có thể không còn kế thừa từ AbstractCollection. | Simpo PDF Merge and Split Unregistered Version - http A dynamic instanceof The method provides a way to dynamically test the type of an object. Thus all those tedious instanceof statements can be removed from typeinfo Using isInstance import . import . import . import static . public class PetCount3 static class PetCounter extends LinkedHashMap Class extends Pet Integer public PetCounter super 0 public void count Pet pet eliminates instanceofs for Class extends Pet Integer pair entrySet if .isInstance pet put 1 . . . . public String toString StringBuilder result new StringBuilder for Class extends Pet Integer pair entrySet .getSimpleName -2 return public static void main String args PetCounter petCount new PetCounter for Pet pet 20 printnb .getSimpleName pet print print petCount . . Output Rat Manx Cymric Mutt Pug Cymric Pug Manx Cymric Rat EgyptianMau Hamster EgyptianMau Mutt Mutt Cymric Mouse Pug Mouse Cymric Pet 20 Dog 6 Cat 9 Rodent 5 Mutt 3 Pug 3 EgyptianMau 2 Manx 7 Cymric 5 Rat 2 Mouse 2 Hamster 1 In order to count all the different types of Pet the PetCounter Map is preloaded with the types from . This uses the class which takes an Iterable the allTypes List and a constant value zero in this case and fills the Map with keys taken from allTypes and values of zero . Without pre-loading the Map you would only end up counting the types that are randomly generated and not the base types like Pet and Cat. Type Information 411 Simpo PDF Merge and Split Unregistered Version - http .

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.