This is probably something really simple, but I'm obviously not getting it...
I have the following example:
I've tried every permutation that I can think of, and I can't seem to get rid of:
Any ideas what I'm missing? The code works and I end up with what I want, but I would prefer to fix the warnings (as opposed to simply suppressing them).
You will get warnings one or the other way, because you are mixing raw types with parameterized types.
Why not using two HashMaps? One that holds the String, Map combo, and the other the String, List.
Well, it gets more evil because I got this to work:
You gotta love it
I think that the problem is trying to define things too early. What seems to work best (for me) is to keep the types closer to the actual definitions. In other words, rather than trying to define the whole HashMap up front (ala HashMap<String, HashMap<String, HashMap<String, String>>>, although I may not have tried that one... ), get more specific as I get to where I'm actually defining the maps/lists.
Am I reading this right? You are creating an anonymous inner class that extends the HashMap class, for the purpose so that, you can add an instance initializer, that preloads two key value pairs?
Creating a new class, just so that you can initialize a particular instance is a bit much, isn't it?
Oh, and by the way, the reason this looks so evil is because I'm reading in a configuration file that has multiple types of parameters it defines (it's also inconsistent in it's definitions...I didn't write it) with variable arguments and lists for the different parameters. But I want to keep all of the information in a single map.
Maybe it'd be cleaner to create a general "configuration parameter" interface with multiple implementations?
No, I guess you don't "gotta love it". I just thought it was funny that it actually worked
Here's another stab at it...I think this is better, but it could probably still be improved on:
In case it wasn't obvious, I'm new to Java...so sometimes I play with things just to see what happens. I guess I got a little carried away. Sorry.
When I compile the above I end up with a test_generics$Config.class, which I understand (I think), but I also get a test_generics$1.class, what's that?
I'm not sure I follow you. What do you mean by a "configuration parameter interface"? I am trying to figure out how to read in the config file and hold the information somewhere, but I will actually just create an instance of "ConfigFile" and use "get" methods to give me the pieces I need...Is that what you're talking about?
Using your old implementation you had some of them. I can't spot any anonymous classes in your code, maybe the class file is from the old implementation...
First of all, notice how I removed the references to HashMap in the variable type and the generics. It makes it possible to switch to TreeMaps or LinkedHashMaps later on. Second, the generic value type for the inner map must be Object because you want to put anything in it. Anything else will not work.