Code example for PriorityQueue

Methods: offer

0
 
    /** 
     * @tests java.util.PriorityQueue#offer(Object) 
     */ 
    public void test_offer_Ljava_lang_Object_non_Comparable() { 
        PriorityQueue<Object> queue = new PriorityQueue<Object>();
        queue.offer(new Integer(10));
        try { 
            queue.offer(new Float(1.3));
            fail("should throw ClassCastException");
        } catch (ClassCastException e) {
            // expected 
        } 
 
        queue = new PriorityQueue<Object>();
        queue.offer(new Integer(10));
        try { 
            queue.offer(new Object());
            fail("should throw ClassCastException");
        } catch (ClassCastException e) {
            // expected