Forum Stats

  • 3,760,204 Users
  • 2,251,664 Discussions
  • 7,871,021 Comments

Discussions

treeset

843793
843793 Member Posts: 41,732 Green Ribbon
edited Apr 15, 2010 3:11AM in Generics
TreeSet<String> s = new TreeSet<String>();
		TreeSet<String> subs = new TreeSet<String>();
		 s.add("a"); s.add("b"); s.add("c"); s.add("d"); s.add("e");
		
		 subs = (TreeSet) s.subSet("b",true, "d",true);  //1
		 
		 System.out.println(s +" "+ subs);
in line 1 it returns navigableSet but it is casted to treeset which is a subclass of navigableset so
why doesn't it returns classcastexception?

Comments

This discussion has been closed.