Peter Reilly wrote:
[EMAIL PROTECTED] wrote:
I had a project where a code generator inserts one interface statement - and that
what missing. So I created just an empty interface to make the compiler happy. Couldnt
we "backport" the Iterable interface?
I played a little with these... - build.xml - src\oata\Iterable.java - src\oata\MyClass.java
Nice, but not useful in ant core (kernel) until we move to using java 1.5+ as we would not be able to use java 1.5+ to create an ant distribution that can be used for java 1.4 and previous.
How about (in a java15 package), we have a class that uses reflection to look for the iterator() operator
Class IterateOver implements Iterable {
Object instance;
IterateOver(instance) {this.instance=instance}
public Iterator iterator() { Class clazz=instance.getClass(); Method method=clazz.getMethod("iterator"); return method.invoke(instance); }
}
you could then do (for e:new IterateOver(something));
not ideal, I admit. Oh, there is all that generic typing stuff too. sigh.
Just checked the language spec
1. you can have any expression that returns an iterable. So a static method
makeIterator(Object instance) {return new IterateOver(instance);}
would work too
for(type t:makeIterator(anInstance)) would work
The problem is that typing is not going to work right, you need a language which is either fully untyped (python, &c), or one with like standard ML, in which types are primary objects you can work with.
2. you can iterate over arrays. So if we have operators that return typed arrays, you can iterate over them
-steve
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]