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
toImmutableBinaryTree
song must satisfy the bounds of the type parameter onImmutableBinaryTree
, meaning it must implement theComparable
interface since the type parameter specifies the boundsT extends Comparable<T>
.