What are generics in Java?

In this lesson, we talk about generics. Or rather, about the basics that you need to know when diving into generics: what generics are and why you need them at all. The topic is very important, and you definitely need to understand it. Forward!

Generics for cats

Generics are a great tool to help developers hint additional information to the compiler for type safety and flexibility. This in-depth article, written by a member of the CodeGym community, takes another lap around "generics".

Type erasure

This lesson is devoted to some features of generics as well as pitfalls that arise when working with them. Because generics were not part of Java when the language was created, type erasure has been added. What's that? We'll figure it out.

Wildcards in generics

Wildcards are a very important feature of generics and definitely deserve a separate lesson. This is an interesting and simple topic. You're going to love it :)

Using varargs when working with generics

Using varargs with generics can lead to rather unpleasant consequences — heap pollution. In this lesson, we conclude our discussion of various features of generics in Java.

undefined
4
Task
Java Core, level 5, lesson 4
Locked
Something superfluous
Our program is once again full of unnecessary lines of code. Let's correct this blunder by removing all the extra methods, so that the program displays text (and only the text) that corresponds to the task conditions. By the way, you need to get used to this. Junior developers' special ability to create unnecessary code is pretty annoying to senior developers.
undefined
8
Task
Java Core, level 5, lesson 4
Locked
OOP: Method overloading
Let's display matrices in different ways, however we want. OOP gives us a wonderful tool for this: method overloading. Overload the printMatrix method in 8 different ways. You should end up with 10 different printMatrix methods.
undefined
4
Task
Java Core, level 5, lesson 4
Locked
OOP: Method overloading - Eliminating the superfluous
Not every overloaded method is useful. And so it is in this program. Look at the code and think about which implementation of the print method will be called. Then remove all the superfluous implementations of the method - and you're done.
undefined
4
Task
Java Core, level 5, lesson 4
Locked
Man or woman?
Something in this program isn't right... It seems to display the names of men, but not those of women. Put an end to the discrimination: change the printName method so that it runs for both man and woman. The method should have a single implementation.
undefined
4
Task
Java Core, level 5, lesson 4
Locked
Be gone, all that is unnecessary!
Again, we have extra lines in a program. They've resulted in a bug, because the program tries to call the add method for cases for which it is not implemented. We won't override the superfluous add methods this time. We'll do something simpler: delete the lines for which there is no implementation.