Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE205 Lecture 18

CSE205 Lecture 18

Object-Oriented Programming and Data Structures
Generics
(202111)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 28, 2021
Tweet

Transcript

  1. jgs CSE 205 Object-Oriented Programming and Data Structures Lecture 18:

    Generic-Data Types, Stack, and Queue Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs Previously …

  3. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 3 jgs

    Program.java
  4. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 4 jgs

    Class MyList
  5. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 5 jgs

    Class MyNode
  6. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 6 jgs

    I introduce you a List, a Linked List
  7. jgs Next

  8. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 8 jgs

    Definition § Generics or parameterized types. § The idea is to allow type (Integer, String, … etc., and user-defined types) to be a parameter to methods, classes, and interfaces. § Using Generics, it is possible to create classes that work with different data types. § An entity such as class, interface, or method that operates on a parameterized type is called a generic entity.
  9. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 9 jgs

    class Test<T, U> { T obj1; // An object of type T U obj2; // An object of type U Test(T obj1, U obj2) { this.obj1 = obj1; this.obj2 = obj2; } public void print() { System.out.println(obj1); System.out.println(obj2); } }
  10. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 10 jgs

    class Main { public static void main (String[] args) { Test <String, Integer> obj = new Test<String, Integer>(”ABC", 15); obj.print(); } }
  11. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 11 jgs

    Generic Data Types
  12. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 12 jgs

    Generic Data Types
  13. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 13 jgs

    Generic Data Types
  14. jgs Stack

  15. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 15 jgs

    I introduce you a List, a Linked List
  16. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 16 jgs

    I introduce you a List, a Linked List
  17. jgs Queue

  18. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 18 jgs

    I introduce you a List, a Linked List
  19. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 19 jgs

    I introduce you a List, a Linked List
  20. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 20 jgs

    Questions
  21. jgs CSE 205 Object-Oriented Programming and Data Structures Javier Gonzalez-Sanchez,

    Ph.D. javiergs@asu.edu Fall 2021 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.