I found this code in CodeGuru : http://codeguru.developer.com/java/articles/364.shtml I uses interfaces to simulate array of functions. Author: Real Gagnon Author's WebSite: http://tactika.com/realhome/realhome.html A technique for simulating an array of functions. public class testf { public static void main(String args[]){ Command[] commands = new Command[3]; commands[0] = new aCommand(); commands[1] = new bCommand(); commands[2] = new cCommand(); commands[0].exec(); commands[1].exec(); commands[2].exec(); } } class aCommand implements Command { public void exec() { System.out.println("a"); } } class bCommand implements Command { public void exec() { System.out.println("b"); } } class cCommand implements Command { public void exec() { System.out.println("c"); } } interface Command { void exec(); } -----Original Message----- From: [Hugo A. Garcia] [mailto:[EMAIL PROTECTED]] Sent: Thursday, November 18, 1999 3:59 PM To: [EMAIL PROTECTED] Subject: Re: Q: Any way to simulate array of pointers ... I am not entirely clear but this sounds like a problem that can be solved by using the Strategy pattern. -H Please respond to "A mailing list for discussion about Sun Microsystem's Java Servlet API Technology." <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] cc: (bcc: Hugo Garcia/RT/FIS) Subject: Q: Any way to simulate array of pointers ... ... to functions (as in C) in Java ? Hi gurus, The problem : Want to initialize an array (or other data structure), either thru code, or by reading from a text file/properties file. Each element will contain the name of a program option to run, and the name of a corresponding Java method that implements that program option. Then I display the names of the options to the user and allow them to select 1 or more options to run. After they click a button to confirm, iterate thru the array and call each of the methods corresponding to the options selected, and display their output to the user. This is basically for a status display facility, to be implemented using servlets and HTML forms, with the options displayed as a list of items with checkboxes alongside. The user will check a box to enable execution of the corresponding option. The same servlet will be called with the selected options as parameters to the URL, and will extract the parameters, and scan thru the array and execute the matching option methods. The idea is to make the program extensible without modifying the main loop; should just be able to add a name/method entry to the text file, write/compile the new class/method for the new option, and it should get displayed/ executed on the next run of the program. Hope it's clear. Is it possible thru reflection or any other way ? TIA ++++++++++++++++++++++++++++++++++++++++++++++++ Vassudev Infosys Technologies Limited, Pune, India [EMAIL PROTECTED] ---------------------------------------------------------------- On a clear day you can see the blue screen of death ++++++++++++++++++++++++++++++++++++++++++++++++ ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
Re: Q: Any way to simulate array of pointers ...
Homero Alejandro Leal Torres Sat, 16 Jan 1999 16:50:42 -0800
- Q: Any way to simulate array of pointers ... RVASUDEV
- Re: Q: Any way to simulate array of poin... Michal Mosiewicz
- Re: Q: Any way to simulate array of poin... [Hugo A. Garcia]
- Re: Q: Any way to simulate array of poin... Homero Alejandro Leal Torres
- Re: Q: Any way to simulate array of poin... Vikas Deep Sharma
