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!
Preview
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
[MUSIC]
0:00
Hi, I'm Ben, and in this course,
we're going to learn about generics.
0:00
But before we get to any formal
definitions, I think it'll help if
0:05
we start by looking at an example of
the problem generics try to solve.
0:08
Let's start by creating a new project.
0:12
And let's click Next.
0:17
Select the template.
0:19
Hit Next again.
0:22
And let's name our project Generics.
0:23
And we can leave the package
as com.teamtreehouse.
0:26
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