This is an old revision of the document!
From the aspect Basics
, declare that the class Application
implements the interface Iterable<String>
.
declare parents: Type implements Type
.
This will raise a compiler error since Application
does not provide an implementation for the iterator()
method prescribed by the interface. We will also provide an implementation for this method from the aspect.
First, declare a public field name
of type String
for the Application
class, with the default value “MyApplication”.
.
).
Next, add a method iterator()
with return type Iterator<String>
. This method will return an iterator over the values of the two fields of the Application
class. To construct this iterator, you can employ the following snippet inside the method body:
java.util.Arrays.asList(name, "go: " + go).iterator();
The declaration of this method should resolve the previous compiler error. To test the new code, add a new class ApplicationTest
with the following implementation:
public class ApplicationTest { public static void output(Application t) { for(String s: t) System.out.println(s); } public static void main(String[] arg) { Application t1 = new Application(); Application t2 = new Application(); t2.name = "YourApplication"; output(t1); output(t2); } }