Sanchit Garg
Sanchit Garg

Reputation: 65

Java collection Type mismatch: cannot convert from TreeSet to SortedSet

package collection;

import java.util.*;

public class SortedSet {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

         SortedSet set = new TreeSet();

    }

}

It giving me following error:

Type mismatch: cannot convert from TreeSet to SortedSet

Upvotes: 3

Views: 1064

Answers (2)

abioticGirl
abioticGirl

Reputation: 188

You have two options: - change the name of class, - change type of set to TreeSet like TreeSer set = new TreeSet();

Upvotes: 1

Eran
Eran

Reputation: 393811

Your class name is also SortedSet, so it is hiding java.util.SortedSet. Either rename your class (the preferred option) or use the full name of the interface in your variable declaration.

Upvotes: 3

Related Questions