Xxx.java:Recompile with-xlint:unchecked for details.

Source: Internet
Author: User


First, encounter problems:
When using ant to perform the build.xml of the Jasperreport Samples/charts sample, it fails to compile with the following error:
Javac
[Javac] Compiling 2 source files to E:/jiangcm/workspace-forict-myeclipse/jasperreports/demo/samples/charts
[Javac] Note: E:/jiangcm/workspace-forict-myeclipse/jasperreports/demo/samples/charts/chartsapp.javaa non-checked or unsafe operation was used.
[Javac] Note: To learn more, recompile with-xlint:unchecked.

Second, check the information, know that the cause of the generic, the online search solution mainly has the following:
1. Compile-time with the parameter-source 1.4
1. Role@SupressWarnings ("unchecked")Comments
3. Update your code, using List<object>. An instance of list<object> can accept any type of object, as if it were a prototype list. However, the compiler does not error.
(Above three methods Source: http://www.matrix.org.cn/resource/article/43/43634_java_generics.html)

4. If you use theAnt, using Build.xmlCompile the words, you can right-click the Build.xml file,
-----Make and execute, select parameters,Enter-xlint:unchecked in "program parameters"To

5. Find a similar statement inside Build.xml, plus a sentence:
<!--Java Compile--
<target name= "Compile" depends= "init" >
<javac srcdir= "src" destdir= "${classdir}"
Deprecation= "on" encoding= "windows-31j" debug= "on" includes= "**/jp/**" >
<compilerarg value= "-xlint:unchecked"/> ' <!--is this sentence!! -
<classpath refid= "Project.class.path"/>
</javac>
</target>
(Source of both methods: http://www.itwenku.com/java/12/47796.htm)

Iii. Self-Test and conclusion

The first type:
"Compile-time with parameter-source 1.4" method of Use:
Find a similar statement inside Build.xml, plus a sentence:
<javac srcdir= "${src.dir}" destdir= "${classes.dir}" >
<classpath refid= "Classpath"/>
<compilerarg line= "-source 1.5"/> ' <!--that's the word! Note that unlike the fifth way, the line label is not value! -
</javac>
Compile the pass, the report under charts appears!

The second type:
"Use @supresswarnings (" unchecked ") Comment:
This comment is added to the main function of Chartsapp.java, but it does not work, and the hint error remains "[Javac] Note: To learn more, use-xlint:unchecked to recompile. "And what's going on?"

Found the answer in an article:
Http://www.matrix.org.cn/resource/article/43/43864_Generic_Types.html
At the time of writing this article, Javac does not support @suppresswarnings annotations. Expect to be supported in Java 5.1.

The third type:

1. Before JDK5.0. We can write vector v in this way without a problem. But after 5.0, a generic will be written as a vector <T> such as a String that is put in a vector <String> it will know the type there is no such warning.
Such as:

Public Vector <StockData> Myvector; Over here
Myvector = new Vector <StockData> (); And here it is.


2. Change the code to use generic mode:
The original code:
Map parameters = new HashMap ();
Parameters.put ("Maxorderid", New Integer (12500));
The changed code:
map<string,integer> parameters = new hashmap<string,integer> ();
Parameters.put ("Maxorderid", New Integer (12500));
Or:
map<object,object> parameters = new hashmap<object,object> ();
Parameters.put ("Maxorderid", New Integer (12500));

After the change, smoothly through the compilation, also can see the report!!

Java uses unchecked or unsafe operations
Import java.util.*;
Class Testvector
{

{
int b=0;
Vector v=new vector ();
System.out.println ("Please enter Number:");
while (true)
{
Try
{
B=system.in.read ();
}
catch (Exception e)
{
E.printstacktrace ();
}
if (b== ' \ r ' | | b== ' \ n ')
Break
Else
{
int num =b-' 0 ';

}

int sum=0;
Enumeration e=v.elements ();
while (E.hasmoreelements ())
{
Integer intobj= (integer) e.nextelement ();
Sum+=intobj.intvalue ();
}
SYSTEM.OUT.PRINTLN (sum);
}
}
I can run here and estimate the problem of generics: You will

Enumeration e=v.elements (); instead: Enumeration<integer> e=v.elements ();

The fourth type:

Verified invalid;

The fifth type:
<javac srcdir= "src" destdir= "${classdir}"
deprecation= "on" encoding= "windows-31j" debug= "on" includes= "**/jp/**" >
<compilerarg value= "-xlint:unchecked"/> ' <!--is this sentence!! -
<classpath refid= "Project.class.path"/>
</javac>

Add "<compilerarg value="-xlint:unchecked "/>", after the "warning", but the compilation passed, you can see the report!
The compile prompt is as follows:
[Javac] Compiling 2 source files to E:/jiangcm/workspace-forict-myeclipse/jasperreports/demo/samples/charts
[Javac] e:/jiangcm/workspace-forict-myeclipse/jasperreports/demo/samples/charts/chartsapp.java:115: Warning: [Unchecked] A call to a put (k,v) that is a member of the normal type java.util.Map is unchecked
[Javac] Parameters.put ("Maxorderid", New Integer (12500));
[Javac] ^
[Javac] 1 warning


Hehe, the answer is colorful, all roads through Rome, this time not only solves the problem, but also found four ways to solve the problem.


Resources:
Generics in 1.J2SE 5.0
Budi Kurniawan
Http://www.matrix.org.cn/resource/article/43/43634_java_generics.html
2.Eclipse in the JSP in the error "to learn more information, please use-xlint:unchecked recompile", specifically on the menu how to do?
Http://www.itwenku.com/java/12/47796.htm
3. Generic type, first part
Author: David Flanagan
Http://www.matrix.org.cn/resource/article/43/43864_Generic_Types.html
4. FAQ about Ant
Http://www.blogjava.net/luckyrobbie/articles/24117.html

Q. How do I pass-xlint or-xlint:unchecked to 1.5 javac task?
A:pass it as Compilerarg nested <compilerarg> to specify.

<compilerarg value= "-xlint"/>
<!--or--
<compilerarg value= "-xlint:unchecked"/>

Xxx.java:Recompile with-xlint:unchecked for details.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.