Bound Mismatch Error: The Type is not a valid substitute
Task: I want to store "Song class object" in ImmutableSet through PlayList class.
I have three classes.
public class ImmutableBinaryTree< T extends Comparable<T>> implements ImmutableSet<T> { }
public class Song { }
public class PlayList<T extends Comparable<T>> {
private Song songs;
ImmutableSet<Song> immutableSet; // Bound Mismatch error occurring here
If you are adding a Song
to ImmutableBinaryTree
song must satisfy the bounds of the type parameter on ImmutableBinaryTree
, meaning it must implement the Comparable
interface since the type parameter specifies the bounds T extends Comparable<T>
.
public class Song implements Comparable<Song>{
@Override
public int compareTo(Song arg0) {
//provide implementation here
//See effective java for appropriate implementation conditions
return 0;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With