generics - Java 1.4 to Java 1.5 - Rewrite code and avoid the @SupressWarnings -
I have an old private project written in Java 1.4, which I'm porting to 1.5 (in which I now Also newbie) Version 2. In addition to adding new features and refactoring code in it, I am also migrating for generic collection, annotation etc.
A special part of the code that I do not know is that 1.5 and do not want to add a @SupressWarnings to it. It happens in this way:
if (value is comparable to the example) {isMatch = ((comparative) value) .compareTo (selectedValue) == 0); } Else {// fallback is equal to match = selected value.equals (value); }
This is a simple comparison with a broad match compared to comparison or relative is equal to par () if not, then comparative type.
I am getting: Comparative is a raw type of normal type of reference Comparable & lt; T & gt;
must be an alert parameter.
How do I modify the above code to 1.5 and clear the warning? Or is there no alternative to add @SuppressWarnings?
Thank you!
I would have to rewrite this piece of code in this way:
if (value example is comparable & lt ?? & gt;) {// & lt; - Notice & lt ;? & Gt; // Announce the local version and put it here. // You will be warned, but it is localized for an example // // It is not safe to say that this cast is safe because it matches comparative // @SuppressWarnings in Java 1.4 "uncontrolled") comparative & lt; Object & gt; Comp = (comparison & lt; object & gt;) value; // Now you can use compareTo isMatch = (comp.compareTo (selectedValue) == 0); } Else {// fallback is equal to match = selected value.equals (value); }
Comments
Post a Comment