wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why would the code below not run? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why would the code below not run?" Watch "why would the code below not run?" New topic
Author

why would the code below not run?

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
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

Joined: Aug 03, 2002
Posts: 7729
You have forgotten to put () after the new IntHolder.
What did the compiler say when you compiled it?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Thomas Drew
Ranch Hand

Joined: Sep 15, 2004
Posts: 47
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why would the code below not run?