Results 1 to 9 of 9
- 03-22-2011, 03:55 PM #1
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
Declaring a method inside a method: Runnable?
I have come across a blog in which it is claimed that using the above detailed technique on can run a method inside a method. Is this true. If it is can some take a moment to explain the code above.Java Code:public class SomeClass { public void sayHello ( ) { final Runnable greeter = new Runnable ( ) { public void run ( ) { System.out.println("Hello"); System.out.println("Good Morning"); System.out.println("How Are You"); } } ; greeter.run() ; // first time greeter.run() ; // second time }//sayHello() closes }//SomeClass closes here
- 03-22-2011, 04:02 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What you should do is get a tutorial on threading, ..., and read it.
- 03-22-2011, 04:18 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
What does "run a method inside a method" mean?
This would be running a method inside a method, but I'm guesing that's not whatever blog post it is is actually saying:
Java Code:public void myMethod() { myOtherMethod(); } private void myOtherMethod() { Syetem.out.println("Look at me! Look at me!"); }
- 03-22-2011, 04:19 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
Or is it "declare a method inside a method"? As the title says.
In which case any anonymous class defined in a method would count presumably.
- 03-22-2011, 04:29 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,397
- Blog Entries
- 7
- Rep Power
- 17
The entire question is moot; the ability to define a (local) class in the body of a method allows to define other methods inside a method body; have a look:
kind regards,Java Code:public static void main(String[] args) { // <-- an outer method ActionListener al= new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Who'd have thought it?"); } }; al.actionPerformed(null); }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-22-2011, 04:38 PM #6
Senior Member
- Join Date
- Feb 2011
- Posts
- 107
- Rep Power
- 0
@JosAh
You deserve some reputation for that
- 03-22-2011, 04:39 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,451
- Rep Power
- 16
- 03-22-2011, 05:19 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,397
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-23-2011, 04:30 AM #9
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
Update Method inside a GUI?
By Zepher in forum New To JavaReplies: 8Last Post: 02-07-2011, 01:33 AM -
pass value inside method A to method B
By masokis in forum New To JavaReplies: 5Last Post: 09-01-2010, 04:06 AM -
how to return a value from runnable method
By udinulis in forum AWT / SwingReplies: 10Last Post: 07-20-2010, 05:06 AM -
Unable to call paint() from inside method
By Y. Progammer in forum New To JavaReplies: 3Last Post: 03-01-2010, 12:47 PM -
JOptionPane when called from inside the paintComponent() method
By Y. Progammer in forum New To JavaReplies: 10Last Post: 02-28-2010, 01:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks