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

why would the code below not run?

 
sura watthana
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding anonymous class.
the code below will fail to compile.
could somebody give me a reason why would it not run?
then how to make it run?

Thank you

code

IntHolder makeIntHolder(final int i) {
return new IntHolder {
public int getInt() { return i; }
};
}
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have forgotten to put () after the new IntHolder.
What did the compiler say when you compiled it?
 
Thomas Drew
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thank you might have a problem with scope. IntHolder doesn't exist outside of the makeintHolder . I don't thank you would be able to return it unless you declared it outside of makeintHolder.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic