"Build a Simple Android App" was retired on September 15, 2017. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Generics in Java!
You have completed Generics in Java!
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 upRelated 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