Here is what I have worked with so far:
public static Set<? extends Animal> getAllAnimals(String pathToAnimals)
{
    Set<Animal> returnSet = new HashSet<>();
    File packageFolder = new File(pathToAnimals);
    if(packageFolder.isDirectory())
    {
        try
        {
            for (File file : Objects.requireNonNull(packageFolder.listFiles()))
            {
                if (file.getName().endsWith(".class"))
                {
                    URLClassLoader loader = new URLClassLoader(new URL[]
                            {
                                    new URL(file.getAbsolutePath())
                            });
                    Class testClass = loader.getClass();
                    Object testObject = testClass.newInstance();
                    if(testObject instanceof Animal)
                    {
                        returnSet.add((Animal) testObject);
                    }
                }
            }
        }
        catch(Exception e)
        {
            System.out.println(e.getStackTrace());
        }
    }
    return returnSet;
}
First of all, this solution is problematic because I'm casting the testObject back to Animal in order to be able to put it into the set, but it should be an object of the class it's supposed to be (i.e. if it is a Cat object, it should go into the set as a Cat object, not an Animal object). But besides that, nothing gets added to the set given that when this is run it just prints a set of empty square brackets. I'm pretty sure I need to use generics here given how the newInstance() method is introduced in the previous lesson. In the above code, I tried replacing some of it like this:
Class<T> testClass = loader.getClass();
T testObject = testClass.newInstance();
if(testObject instanceof Animal)
{
    returnSet.add(testObject);
}
However IDEA underlined a lot of this code and it's just not valid to do it this way. So I'm unsure about how to proceed from here. I have only glanced at the solution to see that it's quite long, which means I may not learn much by looking at it.