If we reimplement PetCreator using lcass literals, the result is cleaner in many ways:
// typeinfo/pets/LiteralPetCreator.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Using class literals
// {java typeinfo.pets.LiteralPetCreator}
package typeinfo.pets;
import java.util.*;
public class LiteralPetCreator extends PetCreator {
// No try block needed.
@SuppressWarnings("unchecked")
public static final List<Class<? extends Pet>> ALL_TYPES =
Collections.unmodifiableList(
Arrays.asList(
Pet.class,
Dog.class,
Cat.class,
Rodent.class,
Mutt.class,
Pug.class,