PDA

View Full Version : Can you do a function literal?



Trinithis
06-23-2007, 09:39 PM
In Java can you do a function literal like you can in JavaScript?

JS example:


var i = (function(){return 10;})();

Twey
06-23-2007, 10:26 PM
No.

Java doesn't support anonymous functions of any kind. If you want to move methods around, you have to use the Method class from the java.lang.reflection package.