Nice TWiki > Doc > CodeExamples > GenericProgrammingBeginnerExample (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before the BeginnerExamples

To compile:   
   nicec --sourcepath .. -d . -a apples.jar apples

To run:
   java -jar apples.jar 
*/

abstract interface Comparable {                  
   boolean better(alike); 
}

<Comparable T> T pick(T a, T b){
   if (a.better(b)) return a; else return b;    
}

class Apple implements Comparable {  
   better(Apple other) = other.rating < rating; 

   int rating;
}

void main(String[] args){
   let a1 = new Apple(rating: 3);
   let a2 = new Apple(rating: 5);
   let a3 = pick(a1,a2);
}

/* Notes - language
Compare with C++, ML, Haskell, Eiffel, Java Generics, Generic C# versions in 
http://www.osl.iu.edu/publications/pubs/2003/comparing_generic_programming03.pdf
*/

-- IsaacGouy - 28 Dec 2003

Topic GenericProgrammingBeginnerExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.2 | > | r1.1 | More }
Revision r1.1 - 28 Dec 2003 - 16:59 GMT - IsaacGouy
Parents: WebHome > CodeExamples
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.