ITPub博客

首页 > Linux操作系统 > Linux操作系统 > about URL and URI

about URL and URI

原创 Linux操作系统 作者:omencathay 时间:2019-07-19 21:36:02 0 删除 编辑
http://java.sun.com/javaone/sf/2007...es/puzzlers.jsp

The second puzzle, aptly titled "More Joys of Sets" has the user create HashMap keys that consist or several URL objects. Again, most of the audience was unable to guess the correct answer.

The important thing the audience learned here is that the URL object's equals() method is, in effect, broken. In this case, two URL objects are equal if they resolve to the same IP address and port, not just if they have equal strings. However, Bloch and Pugh point out an even more severe Achilles' Heel: the equality behavior differs depending on if you're connected to the network, where virtual addresses can resolve to the same host, or if you're not on the net, where the resolve is a blocking operation. So, as far as lessons learned, they recommend:

* Don't use URL; use URI instead. URI makes no attempt to compare addresses or ports. In addition, don't use URL as a Set element or a Map key.
* For API designers, the equals() method should not depend on the environment. For example, in this case, equality should not change if a computer is connected to the Internet versus standalone.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25966/viewspace-53308/,如需转载,请注明出处,否则将追究法律责任。

下一篇: 一 Think in pattern
请登录后发表评论 登录
全部评论

注册时间:2002-10-21

  • 博文量
    48
  • 访问量
    33471