Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How do I do this?|

Name: javaboi 2009-04-23 11:43

Hi dudes, I'm wondering about how I can do something like this in java

func(){print "hi"}
func2(){print " there"}

tab[] funcs = {"func", "func2"}
for(int i = 0; i < 2; i++){
funcs[i]()}

resulting in "hi there"

I think this is called anonymous functions in some other codans.

Name: Anonymous 2009-04-23 13:08

>>8
No, you didn't import Class, the class itself has a lower case first letter, the indentation of the first two functions- above and beyond being ``perversely awful'' is inconsistent with the main function. Your array declaration style implies you are creating a String which encodes or otherwise represents an array of "funcs" where it should be an array of strings, each representing a func. Using a foreach loop for an array with two elements in it not only reduces readability, but effeciency of the program and compiler as well. Catching "Throwable" in itself is a laughable idea, but what is worse is that you have caught it at the end of a main method, and in the catch clause proceed to print out a wholly worthless message before letting the program terminate. Simply adding a throws clause to your main function declaration will be quicker, more elegant and actually provide useful debugging messages if an error occurs. The function names func and func2 do nothing to tell the reader what it is they do and if you were attempting to black box this class for abstraction purposes other programmers would have a relatively difficult time figuring out what they do. Invoking a method with null arguments will produce a compiler cast warning, and as such it is bad style to do so. You should explicitly cast the arguments yourself. On top of all of this, you asked if the program was ``enterprise'' enough and yet makes little use of enterprise best practices and development techniques. func and func2, would be better off as seperate classes that extend an abstract printing class to ensure there is no code duplication and allow for maximum maintainability. The only comment you have is cyptic and by and large would be ignored by any programmer reading and trying to understand this code. You have also enclosed your "funcs" declaration within the try catch block which will render it unusable later in the function should you decide to add to it. I hope you enjoy your Haskell and Lisp, and unemployment.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List