It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why no error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why no error" Watch "why no error" New topic

why no error

Niu Xiuyuan
Ranch Hand

Joined: Jun 08, 2001
Posts: 68

i think it would be occur an UnsupportedOperationException but..everything is ok, why??

Sun Certified Java Programmer<br />Sun Certified Web Component Developer
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Hi, Xiuyuan, the method
public static List unmodifiableList(List list)
Returns an unmodifiable view of the specified list. This method allows modules to provide users with "read-only" access to internal lists. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an
Since you only modify the original list, so there is no UnsupportedOperatonException. If you try to modify the returned list, the exception will be thrown.
Hope it helps,

Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹² at my homepage.

Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="" target="_blank" rel="nofollow"></a>, Java resource, mock exam, forum
I agree. Here's the link:
subject: why no error
It's not a secret anymore!