Forums Register Login

Doubt abt Inner class using with Collections.

+Pie Number of slices to send: Send

The output of above code is

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.

Thanks
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Then how above code compiles and run with perfectly output.
That is what i want to know.
+Pie Number of slices to send: Send
It does not compile for me.
The error (on your line 15) is "cannot find symbol - class MyComparator".

Are you sure that you do not have another MyComparator class somewhere?
+Pie Number of slices to send: Send
Barry Gaunt you are right.
when i compiled same class using NetBeans i got same error.

Thanks
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 849 times.
Similar Threads
High Scores Table
Use of comparator and comparable interface
Printing Object details in for-each loop
comparable and comparator interface
Sorting ArrayList
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:11:58.