Generics: CS 305 & 503 Lecture notes

Data Structures & Algorithms Lecture Notes

15 September 2009 • Generics


Code that attempts to protect against run-time casting errors is even more cumbersome:

Object o = stk.pop()
if (o instanceof String) {
  String str = (String) o;
  // blah blah blah
  }
else {
  // Oh no!
  }

This is also only useful if a casting error has a response other than run-time explosions.


This page last modified on 24 January 2006.