Penguin
Diff: PolymorphicTypes
EditPageHistoryDiffInfoLikePages

Differences between version 4 and predecessor to the previous major change of PolymorphicTypes.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 4 Last edited on Tuesday, April 8, 2003 10:13:42 am by DavidHallett Revert
Older page: version 3 Last edited on Tuesday, April 8, 2003 8:47:24 am by SamJansen Revert
@@ -16,9 +16,29 @@
  
 [ML] and [Haskell] have polymorphic typing. 
  
 In [C] you can approximate polymophic typing with __void__ pointer arguments, which will take pointers to any type. In [Java] and [C++] approximate polymorphic typing by using Object classes, which all objects belong to. But in both cases you lose strong type checking, so the quality of your code suffers. 
+  
 ''It should be noted here that this page is talking about what is sometimes known as __parametric polymorphism__. [C++] has templates, which satisfy the definition above, but are known to be syntactic; each instantiation creates a specialised version of the code. In a "true polymorphic system" only one version of the generated code would be used. There are other ways to have polymorphic types, they often come up in ObjectOriented ProgrammingLanguages. Oh, and parametric polymorphism is also often referred to as generics. -- SamJansen'' 
+  
+''Beginning with version 1.5 of the [Java] SDK, [Java] now also supports the concept of generics. -- DavidHallett''  
+%%%%%%  
+__Paramaterized Type__  
+ Vector<String> stringVector = new Vector<String>  
+ List<Integer> integerList = new List<Integer>  
+  
+__Interface__  
+ interface List<Element> implements !MyInterface{...}  
+  
+__Class__  
+ class !MyList<Element> {...}  
+ class !MyList<Element> implements List<Element> {...}  
+  
+__Method__  
+ boolean containsBoth(Element a, Element b);  
+ static <Element> boolean swap(List<Element> list, int i, int j);  
+  
+[Java Generics on developer.java.sun.com|http://developer.java.sun.com/developer/technicalArticles/releases/generics/]  
  
 !!!An Example 
  
 This is Glyn defining a binary tree type on his [Ocaml] interpreter: