Lecture Notes for May 8 Roger Midmore Final Exam 5/17 Wed. 12:25-2:25 Noland Contributions of Pizza To Java's Design --------------------------------------- 1. Parametric Polymorphism 2. Bounded Polymorphism 3. First Class Functions 4. Algebraic Data Types Polymorphism ------------ Pizza added Polymorphism to make it's code more reusable Interface Comparable{ boolean equals(Object O); boolean less(Object O); } Class LinkedList implements Comparable{ T value; LinkedList next; } calling the constructor will set both LinkedList and Comparable to what ever dataType you want. LinkedList L1=new LinkedList(123); First Class Functions --------------------- Class Fct{ static int f(int i){return 2+i;} } First Class Functions are called like in ML Fun(T1,T2,T3)->T0 val static (int)->int g=f; static int call((int)->int f, int i) return f(i); They take the form of (T1,a1,T2,a2,..)->T0 { body } delayed evaluation static(int)->int Compose((int)->int f,(int)->int g){ Fun(int i)->int{ return f(g(i));} Algebraic Data Types -------------------- in ML they take the form 'a List=null|node of ('a*'a List) in Pizza Class List{ case nil; case node(char head,List tail); int Length(){ switch(this) case nil=return 0; case node(T,List t) return 1+t.length; } Enumeration ----------- Class color{ case red; case blue; case green; String toString(){ switch(this) case=red return "red"; case=blue return "blue"; case=green return "green"; } }