Previous Lecture Complete and continue  

  Universal Reference Type - Object

Discuss the Universal Reference Type (Object). Compare it to generic (since Java JDK 1.5).

Download

Comparison of Object Reference Type and Generic:

(Also Try to make string comparison for Date objects)

Run-Time Error in Figure B(a) Case:

An exception occurs.


Compilation Error in Figure B(b) case:

Runtime error if we use a Comparable Reference Object (Date2 object which can override compareTo() but didn't). The compilation passed but it will use the original compareTo() method and get type mismatch:

Overriding the compareTo() method to allow String to be compared to Date type. This maybe useful if we define the string comparison for Date type objects:

0 comments