User Tools

Site Tools


basics:ex7

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

basics:ex7 [2007/02/25 17:04]
bdefrain
basics:ex7 [2021/02/05 13:49]
Line 1: Line 1:
-====== The Basics: Exercise 7 ====== 
  
-From the aspect ''Basics'', declare that the class ''Application'' implements the interface ''Iterable<String>''. 
- 
-<note tip> 
-Employ the form ''declare parents: //Type// implements //Type//''. 
-</note> 
- 
-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". 
- 
-<note tip> 
-The inter-type declaration of members (fields or methods) has the same syntax as the ordinary declarations of members, but the method or field name must be prefixed by name of the receiving class and a dot (''.''). 
-</note> 
- 
-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: 
- 
-<code aspectj> 
-java.util.Arrays.asList(name, "go: " + go).iterator(); 
-</code> 
- 
-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: 
- 
-<code aspectj> 
-public class ApplicationTest { 
-  public static void main(String[] arg) { 
-    Application t = new Application(); 
-    t.name = "YourApplication"; 
-    for(String s: t) 
-      System.out.println(s); 
-  } 
-} 
-</code> 
- 
-To start this new ''main'' method, right-click on the class ''ApplicationTest'' and select **Run As** -> **Java/AspectJ Application**. 
- 
----- 
- 
-Continue with the [[invariants:intro|Invariants]] track. 
basics/ex7.txt ยท Last modified: 2021/02/05 13:49 (external edit)