Object-Oriented Programming with Java Lecture Notes

25 March 2008 • Generics


This seems so idiotic as to be unbeleivable. Here's some evidence in support:

$ cat x.java
class Mailbox<T> { }

class t {
  void lock(Mailbox<Object> mb) { }

  void t() {
    lock(new Mailbox<Object>());
    lock(new Mailbox<Integer>());
    }
  }

$ javac x.java
x.java:8: lock(Mailbox<java.lang.Object>) in t cannot be applied to 
(Mailbox<java.lang.Integer>)
    lock(new Mailbox<Integer>());
    ^
1 error

$ 


This page last modified on 24 January 2006.