I have some classes (Car, Motorcycle, Train ... etc) that extends from class Vehicle.
From another Class I need to create an ArrayList of Classes for access only to those that inlude the ArrayList.
The concept is similar to this, but obviously it doesn't work;
ArrayList<Class> vehicleType=new ArrayList<Class>();
vehicleType.add(Class.forName("train"));
How can I solve it ? Thanks
ArrayList<Vehicle>do what you want?Trainand yourforName()call specifiedtrain, which doesn't match in the first letter?ArrayList<Class<? extends Vehicle>>.