Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bound Mismatch Error: The type is not a valid substitute

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
like image 568
user3094713 Avatar asked Dec 12 '13 09:12

user3094713


1 Answers

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;
    }

}
like image 160
Kevin Bowersox Avatar answered Oct 16 '22 20:10

Kevin Bowersox