# Error: Hashtable Type safety: The method put(Object, Object)



## Gast^stätte (12. Jul 2007)

Hallo,

folgende codezeilen z.b. verursachen untenstehende Fehlerzeilen:

```
Hashtable env = new Hashtable(); 

String keystore = "C:/Programme/Java/jre1.6.0_01/lib/security/ZertifikatBerlin System.setProperty("javax.net.ssl.trustStore",keystore);	
	 
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldaps://rhein:636");
env.put(Context.SECURITY_PROTOCOL,"SSL");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, adminUser);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
```

Kann mir jemand sagen was ich falsch mache, ich hätte schwören können, dass mir eclipse 3.2.2 dies nicht moniert hat sondern nur 3.3 ganz neu...


```
Severity and Description	Path	Resource	Location	Creation Time	Id
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 123	1184243264915	2593
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 124	1184243264915	2594
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 125	1184243264915	2595
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 126	1184243264915	2596
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 127	1184243264915	2597
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 128	1184243264915	2598
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 129	1184243264915	2599
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 288	1184243264915	2607
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 289	1184243264915	2608
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 290	1184243264915	2609
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 291	1184243264915	2610
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 292	1184243264915	2611
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 293	1184243264915	2612
Type safety: The method put(Object, Object) belongs to the raw type Hashtable. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 294	1184243264915	2613

NamingEnumeration is a raw type. References to generic type NamingEnumeration<T> should be parameterized	LDAP	MainWindow.java	line 144	1184243264915	2601
NamingEnumeration is a raw type. References to generic type NamingEnumeration<T> should be parameterized	LDAP	MainWindow.java	line 194	1184243264915	2602
NamingEnumeration is a raw type. References to generic type NamingEnumeration<T> should be parameterized	LDAP	MainWindow.java	line 206	1184243264915	2603
Hashtable is a raw type. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 117	1184243264915	2591
Hashtable is a raw type. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 117	1184243264915	2592
Hashtable is a raw type. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 282	1184243264915	2605
Hashtable is a raw type. References to generic type Hashtable<K,V> should be parameterized	LDAP	MainWindow.java	line 282	1184243264915	2606
```


----------



## Murray (12. Jul 2007)

Der Compiler warnt nur davor, dass Hashtable ohne weitere Qualifizierung nicht typsicher ist und daher besser parametrisiert werden sollte, um eben doch typsicher arbeiten zu können.


```
Hashtable<String,String> env = new Hashtable<String,String>();
```


----------



## Gast^stätte (12. Jul 2007)

ähm da komm ich jetzt nicht ganz mit...

Was für Strings soll ich denn hinter Hashtable schreiben ? ich übergebe doch mit methode put die strings und key an die hashtable, vor allem warum steht da string,string und nicht object,string?


----------



## Murray (12. Jul 2007)

Hinter "Hashtable" sollst du keine Strings schreiben, sondern in spitzen Klammern zwei durch Komma getrennte Klassennamen. Die erste Klasse definiert den Typ der Keys, die zweite den der Values (in deinem Fall sind beides immer Strings)


----------



## Tobias (12. Jul 2007)

Nennt sich Generics, ist "neu" seit Java 1.5 und gehört zu den Grundlagen, die du im Lehrbuch deiner Wahl nachlesen kannst .

mpG
Tobias


----------



## Guest (13. Jul 2007)

So viel zum Thema Gernerics in Java und Typsicherheit. :autsch: 
	
	
	
	





```
Map<String, Long> map = new HashMap<String, Long>();
map.put("A", 1L);
Object obj = map.get(123d); // Hier könnte man eine Warnung erwarten
System.out.println(obj);
```


----------



## SlaterB (13. Jul 2007)

das Thema hatten wir gerade 
http://www.java-forum.org/de/viewtopic.php?t=52402


----------

