Если коротко, то Hashtable не поддерживает null'ы ни в каком виде:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Hashtable; | |
import java.util.Properties; | |
public class HashtableTest { | |
public static void main(String[] args) { | |
Properties p = new Properties(); | |
if (p instanceof Hashtable) { | |
System.out.println("java.util.Properties is a subclass of java.util.Hashtable"); | |
} | |
try { | |
p.put(null, "value"); | |
} catch (NullPointerException npe) { | |
System.out.println("Hashtable does NOT support addition of null KEYs!"); | |
} | |
try { | |
p.put("key", null); | |
} catch (NullPointerException npe) { | |
System.out.println("Hashtable does NOT support addition of null VALUEs!"); | |
} | |
try { | |
if (!p.contains(null)) { | |
System.out.println("Does not contain null."); | |
} | |
} catch (NullPointerException npe) { | |
System.out.println("Hashtable does NOT support check for null keys!"); | |
} | |
} | |
} | |
/* OUTPUT: | |
java.util.Properties is a subclass of java.util.Hashtable | |
Hashtable does NOT support addition of null KEYs! | |
Hashtable does NOT support addition of null VALUEs! | |
Hashtable does NOT support check for null keys! | |
*/ |
No comments:
Post a Comment