I\'m starting to learn Generics
for Java
and I read several tutorials, but I\'m a bit confused and not sure how a generic method is declared.
Your example shows two different concepts: generic classes and generic methods
This is a generic class introducing a type parameter :
public class Box {
}
While these are generic methods introducing their own type parameter :
public List transform(List in) {
return null;
}
public static A getFirstElement(List list) {
return null;
}
Compare it with a class having a field of a specific name and a method having a parameter of that name:
public class Box {
private String name;
publix Box(String name) {
}
}