Replacement for obsolete Hashtable class in Java

后端 未结 6 1683
夕颜
夕颜 2021-01-01 17:51

When I tried to use the hashtable class, Netbeans gave me an error saying:

While still supported, these classes were made obsolete by the JDK1.2 colle

6条回答
  •  無奈伤痛
    2021-01-01 18:24

    There are cases when a method outside your control requires an Hashtable. Java's own javax.management.ObjectName is such an example[1].

    When the external interface requires it you have to use Hashtable. In netbeans, you can use:

    @SupresssWarnings("UseOfObsoleteCollectionType")
    

    to suppress the warning locally.

    See

    • Java: complete list of @SuppressWarnings(...) parameters (in Netbeans)?
    • Suppress deprecated import warning in Java

    1: I wonder why they used Hashtable and not HashMap, since ObjectName is available since 1.5 and Hashtable is obsolete since 1.2

提交回复
热议问题