Java核心API反模式。哪里不对? [英] Java core API anti-Patterns. What is wrong?
本文介绍了Java核心API反模式。哪里不对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我几本书读过关于Java核心库,失误了一些批评(据我所知)仍然存在的向后兼容性和传统的原因。我想有一个COM prehensive列表,这样的问题是,你知道哪些?
I have read in several books some criticism about mistakes in Java core library that (as far as I know) are still there for backward compatibility and legacy reasons. I would like to have a comprehensive list, so the question is, which ones do you know?
例如:
-
观测
是一类;应的接口,以便允许多个继承。 -
Cloneable的
是一个标记接口,和对象
是克隆的所有者()
方法;相反,的clone()
应该在Cloneable的
接口
Observable
is a class; should be an interface in order to allow multiple inheritance.Cloneable
is a marker interface, andObject
is the owner ofclone()
method; instead,clone()
should be in theCloneable
interface
推荐答案
- 属性扩展哈希表。 AARGH。
- 中的每个对象是可锁定的,而不是具体的锁定对象(.NET有同样的问题)
- 每个有对象相等/哈希code - 再.NET有同样的问题,但至少他们有
的IEqualityComparer< T>
以及的IComparer< T>
。这是所有地图等应该走的路,因为有根据环境平等多个概念。 - 日期/时间API(新版本在Java 7中,我希望)
- NIO的异步模式是难度比异步.NET模型神交
- 没有统一的处理界面 - 部分原因是由于检查的异常 - 这使得使用的声明难以应付(即<一的等效href=\"http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html\">try-with-resources在Java 7中陈述是使用
相当于
,宽) - 可怜的文本编码支持(太多使用的名称作为字符串)
- 无无符号字节型
- Properties extends Hashtable. Aargh.
- Every object being available for locking instead of specific lock objects(.NET has the same problem)
- Every object having equality/hashcode - again .NET has the same problem, but at least they have
IEqualityComparer<T>
as well asIComparer<T>
. This is the way that all maps etc should go, as there are multiple concepts of equality depending on circumstance. - The date/time API (new version in Java 7, I hope)
- The async model of NIO is harder to grok than the async .NET model
- No universal disposal interface - partly due to checked exceptions - which makes an equivalent of the "using" statement harder to cope with (the try-with-resources statement in Java 7 is the equivalent of
using
, broadly) - Poor text encoding support (too much use of names as strings)
- No unsigned byte type
这篇关于Java核心API反模式。哪里不对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文