This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In this video we'll take a look at the kinds of problems we can run into without generics!
Milk.java
class Milk {
void drink() {
System.out.println("You drink the milk.");
}
}
Oranges.java
class Oranges {
void juggle() {
System.out.println("You drop the oranges on the ground.");
}
}
Box.java
class Box {
private Object contents;
void add(Object thing) {
if (contents == null) {
contents = thing;
} else {
System.out.println("The box is full.");
}
}
Object remove() {
if (contents == null) {
System.out.println("The box is empty.");
return null;
} else {
Object thing = contents;
contents = null;
return thing;
}
}
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Korsons Don
3,141 Points1 Answer
-
Jake Lee
2,789 Points1 Answer
-
Erick Luna
21,077 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up