HashMap needs unchecked conversion to conform to HashMap<String, BigDecimal>

Type safety: The expression of type HashMap needs unchecked conversion to

conform to HashMap<String,BigDecimal>

Sorry about the topic but thats all the characters I could fit.

So I'm trying to make sure all the new code I'm producing these days uses generics, because they're cool and casting all the time is lame.

I've got a HashMap<String, HashMap> that is storing HashMap<String, BigDecimal>

In the context where I'm taking the second HashMap out of the first I've got a line like this:

HashMap<String, BigDecimal> fiscalPeriods = object.get(objectNumber);

And the second half of that expression Eclipse doesn't care for and gives me the aformentioned warning.

Object is declared as such:

private LinkedHashMap<String, HashMap> object =new LinkedHashMap<String, HashMap>();

What could/should I be doing better/different here?

[989 byte] By [robpaynea] at [2007-11-27 10:52:10]
# 1

> > private LinkedHashMap<String, HashMap><String, BigDecimal> > object = new

> LinkedHashMap<String, HashMap><String, BigDecimal> >();

>

tjacobs01a at 2007-7-29 11:35:55 > top of Java-index,Core,Core APIs...
# 2

private LinkedHashMap<String, HashMap><String, BigDecimal>> object =

new LinkedHashMap<String, HashMap><String, BigDecimal>> ();

Is apparently working. Much Thanks.

The code tags are putting an extra > in what I'm seeing!

private LinkedHashMap<String, HashMap<String, BigDecimal>> object =

new LinkedHashMap<String, HashMap<String, BigDecimal>> ();

I'm assuming thats why what you posted wasn't exactly right :)

Ok its not just the code tags! There is an extra Greater Than sign after thats not here when I edit the message, but appears when I view the post, very frustrating.

robpaynea at 2007-7-29 11:35:55 > top of Java-index,Core,Core APIs...
# 3

I've got another question.

We've got a class that Extends HashMap and then implements a custom Interface.

Eclipse complains when I put and get things out of this (and rightly so, the only thing I believe I could be fairly certain of is that the key is a String, the value could be ANYTHING):

Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized

But when I try and Parametize the declaration of the object, I get this:

The type CustomDataManager is not generic; it cannot be parameterized with arguments <String, Object>

Now this isn't my class to maintain, so really I'm just trying my best to understand how to use generics in more places and get rid of those yellow underlines eclipse is so found of. I've got the current file I'm working on free of them except for places where I use this data structure.

Any idea what I could do here?

I figured it out myself, in the declaration of the class I can put

public class CustomDataManager extends HashMap<Object, Object> implements ResolverIF

The reason it can't be HashMap<String, Object> is part of implementing the ResolverIF interface is supporting .put(Object, Object)

So really I don't think I gained much here as far as making the code reasier to understand, just a little less yellow in Eclipse.

Message was edited by:

robpayne

robpaynea at 2007-7-29 11:35:55 > top of Java-index,Core,Core APIs...