Troubleshooting Java compile warnings:
As I continue to work with Java, from time to time my source code, when compiled returns the following messages to stdout. This is a fairly common message as I maintain certain source files at work. Here is an example of the particular message.
Note: ArrayListTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Sometimes a programmer will inherit a Java project from another person who in
turn may have got that project from someone else. So we have a hand-me-down
Java source file that when compiled, returns those two notes mentioned above.
The Java compiler is nice enough to tell you that there is a situation there
and to recompile with the -Xlint. The -Xlint will output all the warnings to
stdout. There could be times where it would not be practical to actually run
the -Xlint option. Checking the ant build script may offer a means to use that
-Xlint as a compile option.
Using the -Xlint will be helpful in finding the offending line of Java source
code. For an example, here is a defined array list both the correct way
(commented) and the way that causes those two above compilation notes.
// create an array list
//ArrayList <String> al = new ArrayList<String>();
ArrayList al = new ArrayList();
So when it comes down to it, the coder should keep in mind when inheriting a
project that is a hand-me-down, they may need to keep things in mind like
ensuring data types are declared in such a way so it keeps the compiler happy. Either way the program will run, it is just a really good practice to ensure source compiles clean.
As for me, as I go through this one source file at work, perhaps a few hundred lines or so, I'll know what I'm suppose to be looking for in order to clean up these messages. Maybe I'll be lucky enough and find where in the ant script to insert this compiler option.
No comments:
Post a Comment