In the previous lesson:
https://codegym.cc/quests/lectures/questcollections.level05.lecture03
They use the following block of example code:
class Zoo<T>
{
ArrayList<T> pets = new ArrayList<T>();
public T createAnimal()
{
T animal = new T();
pets.add(animal)
return animal;
}
}
In the above example, the method createAnimal returns a T object, which is a generic.
Why, then, is the method declaration for this task not:
public static T someStaticMethod(T genericObject)
{
System.out.println(genericObject);
return genericObject;
}
This won't even compile, and checking the solution I have to use <T> T instead of just T.
I am trying to understand why the structure in the createAnimal method is different from the structure in this task. Why isn't the createAnimal method public <T> T createAnimal() ?