Community
Participate
Working Groups
I am using a generic linked list GenericList.getLast(); should be an error if not in try block, or in function that with a throw statement. 1) No Error 2) No Quick Fix Thanks Mike
LinkedList.getLast() doesn't declare any exception.
Here is the code for getLast from Java 1.5 beta 2. Thanks Mike /** * Returns the last element in this list. * * @return the last element in this list. * @throws NoSuchElementException if this list is empty. */ public E getLast() { if (size==0) throw new NoSuchElementException(); return header.previous.element; }
---- FYI ---- here is the code from java 1.4 /** * Returns the last element in this list. * * @return the last element in this list. * @throws NoSuchElementException if this list is empty. */ public Object getLast() { if (size==0) throw new NoSuchElementException(); return header.previous.element; } -------------------------------------------------
This is what I said earlier, it does not declare any exception; thus can only throw unchecked exception which a compiler is not reporting. This is described in language specs.