Nice TWiki > Doc > GenericProgrammingBeginnerExample (r1.1 vs. r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic GenericProgrammingBeginnerExample (r1.2 - 10 Jan 2004 - IsaacGouy)
Changed:
<
<

nicec --sourcepath .. -d . -a apples.jar apples

>
>

nicec --sourcepath .. -d . -a generic.jar generic

Changed:
<
<

java -jar apples.jar

>
>

java -jar generic.jar

Added:
>
>

class Orange implements Comparable { better(Orange other) = other.name.compareTo(name) < 0;

String name; }

Added:
>
>

println( a3 + " " + a3.rating );

let o1 = new Orange(name: "Miller"); let o2 = new Orange(name: "Portokalos"); let o3 = pick(o1,o2); println( o3 + " " + o3.name );


 <<O>>  Difference Topic GenericProgrammingBeginnerExample (r1.1 - 28 Dec 2003 - IsaacGouy)
Added:
>
>

%META:TOPICINFO{author="IsaacGouy" date="1072630740" format="1.0" version="1.1"}% %META:TOPICPARENT{name="CodeExamples"}%

/* 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 . { View | Diffs | r1.2 | > | r1.1 | More }
Revision r1.1 - 28 Dec 2003 - 16:59 GMT - IsaacGouy
Revision r1.2 - 10 Jan 2004 - 15:35 GMT - IsaacGouy
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.