Effective Java! Favor Generic Methods

This week’s chapter continues where our last chapter left off. Whereas last week we talked about generic types, this week we discuss generic methods. As it was with making generic types, one of the main goals of using generic methods is to improve the readability and safety of the code which often can be realized by noticing that there are no casts and no unchecked warnings at compile time. So let’s look at some examples.

Let’s look at a method that doesn’t use generics first:

public static Set union(Set s1, Set s2) {
Set result = new