N
neuneudr
Hi again,
I'm using the following class, which works fine for its purpose
but gives a compiler warning.
The following class declaration works:
class Progress<V extends Comparable> implements
Comparable<Progress<V>>
but the following doesn't work :
class Progress<V extends Comparable> implements Comparable<Progress<V
extends Comparable>>
Yet it's something "close" to that I guess I'd need to get rid of
the compiler warning.
Here's the class (simply remove the @Nullable annotation to compile if
you're not using IntelliJ/@NotNull/@Nullable annotations).
What do I need to do to (cleanly) get rid of the compiler warning?
import org.jetbrains.annotations.Nullable;
/**
* The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
* NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
* "OPTIONAL" in this document are to be interpreted as described in
* RFC 2119.
*
*/
public class Progress<V extends Comparable> implements
Comparable<Progress<V>> {
public final int progress;
public final @Nullable V v;
/**
* You MUST either give a null object and a progress between 0 and
100
* (both included) or a non null object and a -1 progress value.
*
* @param progress
* @param v
*/
public Progress( final int progress, final @Nullable V v ) {
if ( (( progress < 0 || progress > 100) && v == null )
|| (( progress >= 0 && progress <= 100 && v != null ))
|| (( v != null && progress != -1 )) )
throwContractFailure();
this.progress = progress;
this.v = v;
}
public int compareTo( final Progress<V> o ) {
if ( progress != -1 || o.progress != -1 ) {
// sorting on values where there's still progress going on
doesn't
// really matter
return progress > o.progress ? 1 : progress < o.progress ?
-1 : 0;
} else {
// THE FOLLOWING LINE GENERATES A COMPILER WARNING:
// "...uses unchecked or unsafe operation"
return v.compareTo(o.v);
}
}
private void throwContractFailure() {
final String err = "The two arguments you gave are incorrect.
Please"
+ "re-read this class's Javadoc.";
throw new IllegalArgumentException( err );
}
}
I'm using the following class, which works fine for its purpose
but gives a compiler warning.
The following class declaration works:
class Progress<V extends Comparable> implements
Comparable<Progress<V>>
but the following doesn't work :
class Progress<V extends Comparable> implements Comparable<Progress<V
extends Comparable>>
Yet it's something "close" to that I guess I'd need to get rid of
the compiler warning.
Here's the class (simply remove the @Nullable annotation to compile if
you're not using IntelliJ/@NotNull/@Nullable annotations).
What do I need to do to (cleanly) get rid of the compiler warning?
import org.jetbrains.annotations.Nullable;
/**
* The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
* NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
* "OPTIONAL" in this document are to be interpreted as described in
* RFC 2119.
*
*/
public class Progress<V extends Comparable> implements
Comparable<Progress<V>> {
public final int progress;
public final @Nullable V v;
/**
* You MUST either give a null object and a progress between 0 and
100
* (both included) or a non null object and a -1 progress value.
*
* @param progress
* @param v
*/
public Progress( final int progress, final @Nullable V v ) {
if ( (( progress < 0 || progress > 100) && v == null )
|| (( progress >= 0 && progress <= 100 && v != null ))
|| (( v != null && progress != -1 )) )
throwContractFailure();
this.progress = progress;
this.v = v;
}
public int compareTo( final Progress<V> o ) {
if ( progress != -1 || o.progress != -1 ) {
// sorting on values where there's still progress going on
doesn't
// really matter
return progress > o.progress ? 1 : progress < o.progress ?
-1 : 0;
} else {
// THE FOLLOWING LINE GENERATES A COMPILER WARNING:
// "...uses unchecked or unsafe operation"
return v.compareTo(o.v);
}
}
private void throwContractFailure() {
final String err = "The two arguments you gave are incorrect.
Please"
+ "re-read this class's Javadoc.";
throw new IllegalArgumentException( err );
}
}