interface Generator<T>

殳经略
2023-12-01
interface Generator<T>
{
T next();
}


class BasicGenerator<T> implements Generator<T>{
private Class<T> type;
public BasicGenerator(Class <T> type) {
this.type = type;
}
@Override
public T next() {
try {
return type.newInstance();
} catch (Exception e) {
throw new RuntimeException();
}
}

// public static <T> Generator<T> create(Class<T> type){
// return new BasicGenerator<T>(type);
// }
}


class CountedObject{
private static long counter = 0;
private final long id = counter++;
public long id() {
return id;
}
@Override
public String toString() {
return "CountedObject [id=" + id + "]";
}

}
 类似资料: