• 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

compiler warning

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in Eclipse IDE, i should get the "unnecessary cast" error warning.



but i use BlueJ, and BlueJ gives me no warnings. running from the command line does nothing either.
so how does eclipse generate warnings?
it's doing the same thing as BlueJ and the command line, right?
(translating from Java code to binary)
so why do i get different results?

how are warnings defined?
 
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abigail,

'Error' and 'warning' are two different things. Usually, an 'error' is a fatal flaw that must be fixed. A 'warning' is just that - an advisement that something could be done better, perhaps, but shouldn't impact the compiling of the program. 'Warning' messages are more IDE developer determined. Eclipse is very sophisticated and has those sorts of 'warnings' to help professional developers streamline their code.

And to clarify your comment, by default, Eclipse won't give you an error or warning because "Unnecessary cast or 'instanceof' operation" is set to be ignored. However, you can adjust the error/warning/ignore parameters in Eclipse using the following instructions: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcompiler%2Fref-preferences-errors-warnings.htm

With BlueJ, I don't remember there being any controls for setting error advisements. Which makes sense considering BlueJ's audience. BlueJ is a very basic IDE used for entry level students. The code you provided will still work and for someone who has just been introduced to OOP (the intended audience of BlueJ) introducing unnecessary casting is probably something a teacher doesn't want to have to explain when they are just trying to learn how to print an int.

For the command line, the code works so for the same reason no error condition will be shown.

Cheers!
Chris

 
Abigail Decan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you, that cleared up a lot for me.

but in that case, why do we say "compiler" warnings, not "IDE warnings"?
it's not the compiler that's giving out the warning, but the settings inside the IDE, right?
or is IDE using the compiler in some way to give the warning?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would be the case of an IDE warning, or "hint", yes.

But there's also something else called "compiler warnings". These are warnings that are generated by the compiler itself, even though the code is legal. Generally IDEs warn about more things than the compiler does.

If you compile your code from the command line, use -Xlint:all to show all compiler warnings. Try this with your unnecessary cast.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic