Generics and Collections
Learn about generics and collections in Java.
StartGenerics: Lesson
Lesson 1 of 2
- 1When using Java, we often write classes and algorithms that work around certain data types. Let’s look at the following class as an example: public class StringBox { public String myString; } I…
- 3Generics allow our programs to adapt to different data type needs but one issue with them is that we cannot use primitive types (int, double, boolean, etc) as arguments to generic type parameters. …
- 4We’ve seen how to create a generic class but we can also create a generic interface. Let’s look at an example: public interface Replacer { void replace(T data); } The generic interface Messenge…
- 7As of now, our generic classes, interfaces, and methods have all taken a single parameter type but what if our program needed to specify two or more parameter types? Java generics allow us to do th…
- 8We’ve seen how generics make our code scalable by allowing us to provide type arguments to classes, interfaces, and methods. What if we needed to restrict what class or interface could be used as a…
- 10Recall that generic code can have an upper bound when defined using a type parameter or a wildcard. We can also provide a lower bound when working with wildcards. A lower bound wildcard restricts…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory