• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gahhhr - stuck ...Generics? OOP-2

 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a little bit of searching and this is what I found about Xlint:unchecked
-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 ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic