Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 568
Sanchit Garg Avatar asked Aug 21 '26 17:08

Sanchit Garg


2 Answers

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.

like image 180
Eran Avatar answered Aug 24 '26 06:08

Eran


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

like image 41
abioticGirl Avatar answered Aug 24 '26 08:08

abioticGirl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!