Results 1 to 3 of 3
- 08-02-2013, 05:39 PM #1
Member
- Join Date
- Jul 2013
- Posts
- 11
- Rep Power
- 0
Style question on implementing interfaces
I'm studying up on Java multithreading and using the Runnable interface with Swing. Most examples look something like this:
Java Code:SwingUtilities.invokeLater(new Runnable () { public void run () { // whatever you need to do } });
Java Code:Runnable myRunnable = new Runnable () { public void run () { // whatever you need to do } }; SwingUtilities.invokeLater(myRunnable);
Your thoughts?
- 08-02-2013, 05:58 PM #2
Re: Style question on implementing interfaces
There's even a third way (and probably still more): you can define a class that implements Runnable and invokeLater(...) a new instance of that class.
Use whichever style you're comfortable with; the first code snippet may make you a little cross-eyed, but it's something Swing programmers are used to seeing. Usually, the anonymous Runnable's run() implementation has just one line: it invokes a method of the containing class.
In employment, these things are often mandated by the company's coding standards.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 08-02-2013, 06:14 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
Question about standard code style
By lenois in forum New To JavaReplies: 9Last Post: 02-08-2013, 04:56 PM -
A question on Interfaces.
By fatabass in forum New To JavaReplies: 4Last Post: 01-28-2012, 01:00 AM -
Question on interfaces
By fatabass in forum New To JavaReplies: 16Last Post: 01-23-2012, 03:33 PM -
Implementing more than one interfaces
By eva in forum New To JavaReplies: 2Last Post: 12-24-2007, 10:50 AM
Bookmarks