Exception in Java platform library

Sometimes I check the Java platform library for inspiration There are many good design solutions, such as this question However, there are also anomalies that should not be imitated Some of them are given in Joshua Bloch's effective Java, Second Edition, such as Java io. Constant interfaces such as objectstreamconstants or Java net. The behavior of the equals method in the URL Do you know any other examples of such exceptions in the Java platform library? Please give as much as possible

Solution

The close () method declaration throws an IOException, which may not be thrown by a rational implementation If thrown, it is very impossible to write a finally block that is handled correctly

java. util. Enumeration and Java util. Iterator is essentially the same thing

Java. Should be discarded util. Vector,java. util. Hashtable and Java util. Dictionary.

Object. The clone () and clonable interfaces are terrible and have many problems

javax. swing. table. Defaulttablemodel is evil

java. io. Serializable defines a strange special convention using the optional private readObject () and writeobject () methods

Never use Java util. Observable.

The finalize () method is abnormal and should be avoided as much as possible

All date / time APIs are poorly designed java. util. At the end of date, almost all methods are discarded java. util. Calendar has a terrible get (int) and set (int, int) method, which takes an integer identifying the field instead of correctly defined getters and setters java. sql. Date and Java sql. Timestamp extends Java. Java in the worst possible way util. Date: the document explicitly tells it to extend but should not be considered an is-a relationship (this is very bad because the purpose of the extension is to define an is-a relationship) In addition, Java sql. Date override form: Java util. Some methods of date throw exceptions, destroy the superclass contract and fail the Liskov replacement principle (the authors may not care much because they don't want the is-a relationship)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>