Before Sorting 3 2 4 1 After Sort By Comparable 4 3 2 1 After Sort By Comparator 1 2 3 4
Only doubt i have in above code is that how i can create instance of inner class(MyComparator)at line 15 without creating instance of outer class(SortTest) class.Because MyComparator is inner class at line 38.
You cannot. But you can convert your inner class MyComparator into a static nested class, and use it as in new SortTest.MyComparator().
By the way, these classes suffer from very high coupling - the tested class cannot exist without the other testing class. [ August 22, 2006: Message edited by: Barry Gaunt ]