3 ms·
Java has always had the ability to reference Class types, and, to instantiate instances of that type using a standard method: Object makeOne (Class fooClass) {
by lucifer 17y ago
Java has always had the ability to reference Class types, and, to instantiate instances of that type using a standard method:
Object makeOne (Class fooClass) { return fooClass.newInstance(); }
You are missing the point of a factory pattern, which is informed by the non-accidental pattern name: 'Factory'.
[edit: using generics it is even type safe]:
<T> T makeOne (Class<T> clazz) { return clazz.newInstance(); }