Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Generics Lecture 17 CS2110 – Spring 2017

Similar presentations


Presentation on theme: "Java Generics Lecture 17 CS2110 – Spring 2017"— Presentation transcript:

1 Java Generics Lecture 17 CS2110 – Spring 2017
Photo credit: Andrew Kennedy Lecture 17 CS2110 – Spring 2017

2 Proposals for adding Generics to Java
Andrew Meyers Nate Foster Turing Award winner Barbara Liskov Finally appeared in Java 5 (2004). PolyJ Pizza/GJ LOOJ …all based on parametric polymorphism.

3 Concatenating Lists Suppose we want to concatenate a list of lists into one list. We want the return type to depend on what the input type is. lists 3 8 7 5 6 2 Return this list 3 6 8 7 5 2

4 Interface Comparable Interface Comparable<T> declares a method for comparing one object to another. interface Comparable<T> { /* Return a negative number, 0, or positive number * depending on whether this is less than, * equal to, or greater than that */ int compareTo(T that); } Integer, Double, Character, and String are all Comparable with themselves


Download ppt "Java Generics Lecture 17 CS2110 – Spring 2017"

Similar presentations


Ads by Google