public class Loader {
private final Class<? extends Annotation> an;
private final ClassLoader cl;
- private final Map<Class<?>, Object> instances = new HashMap<Class<?>, Object>();
private Loader(Class<? extends Annotation> annotation, ClassLoader loader) {
this.an = annotation;
});
}
- public Iterable<?> instances() {
- return(new Iterable<Object>() {
- public Iterator<Object> iterator() {
- return(new Iterator<Object>() {
+ public <T> Iterable<T> instances(final Class<T> cast) {
+ return(new Iterable<T>() {
+ public Iterator<T> iterator() {
+ return(new Iterator<T>() {
private final Iterator<Class<?>> classes = classes().iterator();
- private Object n = null;
+ private T n = null;
public boolean hasNext() {
while(n == null) {
if(!classes.hasNext())
return(false);
Class<?> cl = classes.next();
- Object inst;
+ T inst;
try {
- inst = cl.newInstance();
+ inst = cast.cast(cl.newInstance());
} catch(InstantiationException e) {
throw(new GlobInstantiationException(e));
} catch(IllegalAccessException e) {
return(true);
}
- public Object next() {
+ public T next() {
if(!hasNext())
throw(new NoSuchElementException());
- Object r = n;
+ T r = n;
n = null;
return(r);
}
});
}
+ public Iterable<?> instances() {
+ return(instances(Object.class));
+ }
+
public static Loader get(Class<? extends Annotation> annotation, ClassLoader loader) {
return(new Loader(annotation, loader));
}