Author |
Topic: Java code doubts (Read 1411 times) |
|
mistaken_id
Junior Member
Posts: 132
|
|
Java code doubts
« on: Jul 26th, 2009, 10:57pm » |
Quote Modify
|
public FolderWatcher() { Pref.Bool.WatchFS.evtChanged.add(new Event.Listener<Boolean> () { public void update(Boolean eventData) { /* * FIXME Save preferences and scope registry before we remove the watches; * on Windows that may cause a crash. */ if (! eventData) try { Pref.save(); ScopeRegistry.getInstance().save(); } catch (IOException e) { } setThreadWatchEnabled(eventData); } }); What does this code do ? Could anyone tell me the high level description of this code. I DONT what the exace detaisl of this code Pref.Bool.WatchFS.evtChanged.add is a method .........the above code calls this method. However, instead of passing arguments to the method, a block of code is defined, Is there any term in Java for tihs case. Could anyone tell me what this is called
|
|
IP Logged |
|
|
|
mistaken_id
Junior Member
Posts: 132
|
|
Re: Java code doubts
« Reply #1 on: Jul 26th, 2009, 11:01pm » |
Quote Modify
|
JNotifyListener fsListener = new JNotifyListener() { public void fileCreated(int arg0, String arg1, String arg2) { handleEvent(arg1, arg2); } public void fileDeleted(int arg0, String arg1, String arg2) { handleEvent(arg1, arg2); } public void fileModified(int arg0, String arg1, String arg2) { handleEvent(arg1, arg2); } public void fileRenamed(int arg0, String arg1, String arg2, String arg3) { handleEvent(arg1, arg2); } }; And similarly this code.... it is creating an object...how ever a block of code follows it...what does this mean
|
|
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: Java code doubts
« Reply #2 on: Jul 27th, 2009, 4:20am » |
Quote Modify
|
It is an anonymous inner class. It is a way to define a subclass of a class right where it is used. In this case, it means you are creating a new instance of a subclass of JNotifyListener, but overriding some of its procedures. It is equivalent to the following public void someMethod() { ... // this class has access to some of someMethod's local variables class MyListener extends JNotifyListener { // override these public void fileCreated(int arg0, String arg1, String arg2) { handleEvent(arg1, arg2); } ... (other methods) } ... // create and use an instance of the listener JNotifyListener fsListener = new MyListener(); // for instance someObject.addListener(fsListener); }
|
|
IP Logged |
|
|
|
meetlesli
Newbie
Posts: 2
|
|
Re: Java code doubts
« Reply #3 on: Jul 19th, 2014, 11:09am » |
Quote Modify
|
Thanks Grimbal .. it worked for me
|
|
IP Logged |
|
|
|
|