This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt abt Inner class using with Collections.

 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how above code compiles and run with perfectly output.
That is what i want to know.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry Gaunt you are right.
when i compiled same class using NetBeans i got same error.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic