


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the cmsc 131 fall 2008 course covers the concepts of polymorphism, wrappers, and interfaces in java. It explains how java provides wrappers for primitive types to enable the use of generic routines and interfaces. The document also discusses the importance of code re-use and polymorphism in object-oriented programming. An example is given of implementing a method using the integer class and adapting cat to implement the comparable interface.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr)
CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 1
We may want to treat primitives as though they were objects For example, generic routines can be implemented using interfaces … but they are not usable on primitive types To overcome this problem, Java provides wrappers for primitive types Wrappers: classes whose objects contain single values of the “wrapped type” Wrappers also contain other useful conversion operations (to / from String, etc.) Wrappers included in java.lang: Byte Short Integer Long Float Double Character Boolean
CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 2
CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 3
CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 6
insists that I must implement compareTo method which has the following prototype: int compareTo(Object o) it must return a negative if the current object is less, a positive if the current object is greater or a 0 if they are the same.
Type of all possible objects in any class Shortcoming of (earlier) Java: no good way to say “same type as this”
CMSC 131 Fall 2008 Jan Plane (Adapted from Bonnie Dorr) 7