wu :: forums
« wu :: forums - Java code doubts »

Welcome, Guest. Please Login or Register.
Nov 21st, 2024, 4:29am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: towr, Grimbal, ThudnBlunder, Icarus, Eigenray, william wu, SMQ)
   Java code doubts
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Java code doubts  (Read 1411 times)
mistaken_id
Junior Member
**





   


Posts: 132
Java code doubts  
« on: Jul 26th, 2009, 10:57pm »
Quote Quote Modify 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 Quote Modify 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: male
Posts: 7527
Re: Java code doubts  
« Reply #2 on: Jul 27th, 2009, 4:20am »
Quote Quote Modify 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
*





   
Email

Posts: 2
Re: Java code doubts  
« Reply #3 on: Jul 19th, 2014, 11:09am »
Quote Quote Modify Modify

Thanks Grimbal .. it worked for me
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board