It's not a secret anymore!
The moose likes Cattle Drive and the fly likes Gahhhr - stuck ...Generics? OOP-2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Gahhhr - stuck ...Generics? OOP-2" Watch "Gahhhr - stuck ...Generics? OOP-2" New topic

Gahhhr - stuck ...Generics? OOP-2

Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
I can't seem to find the solution to this.

Let's say, hypothetically, that I have a Map where I store a String as the key, and an Integer object as the value, but I haven't actually told the Map that this is what is going in.

Then I say...

Would this cause my compiler to get sore at me?

My compiler is definitely getting sore, I am just having trouble figuring out how I've managed to offended it.
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
Went back to my compiler. It is telling me the following:

When I recompile as directed, I am told repeatedly (once for every addition to my Map):

I don't actually say someString and someNumber - this is illustratory.

What is it that I am not getting?
[ February 07, 2007: Message edited by: Katrina Owen ]
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
I did a little bit of searching and this is what I found about Xlint:unchecked
Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.

I found that here if it interests you more.

It still compiles, just throws a warning. If you add a above main it will suppress compile time warnings that would otherwise be thrown if the string matches the type of warning, at least that's how I'm reading the language spec. It's here if you want to read more.

From what I can tell of reading both, you can't suppress warnings the spec explicitly says to throw from the compiler, you have to do it in the code with a suppression.

Edited to add, all that is if you don't parameterize.
[ February 07, 2007: Message edited by: Nathan Leniz ]

The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
You can ignore those warnings. Java 5 spits them out when you write Java 4 code with a Java 5 compiler. I think there is a flag you can use when you compile to avoid that, but other than being a nuisance, it's not a problem.

try these:
javac -source 1.4
javac -target 1.4

They worked for me.

If you implement Nathan's suggestion, you won't get the warnings either, but they won't compile for my 1.4 compiler (because of the '@')
[ February 08, 2007: Message edited by: Marilyn de Queiroz ]

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
Thanks both of you - I thought it was a problem with my code being wrong - I don't mind the compiler complaining, as long as I am coding in an acceptable fashion!
I agree. Here's the link:
subject: Gahhhr - stuck ...Generics? OOP-2
It's not a secret anymore!