patternjavaMinor
"Event Binding" in Java employing Lambda
Viewed 0 times
javaemployingbindinglambdaevent
Problem
As I am relativistically new to programming and lack any sort of formal experience in the matter, I was wondering if any of you with a bit more knowledge in the subject would be willing to tell me if the following code is an acceptable way to accomplish a function binding event handler in Java 8.
I admit that the naming conventions in the following code may be slightly off-par, however, it makes sense to me as a free-spirited beginner who cares not for package.thousand_sub-packages.overly_long_class_name_and_full_essay.java.
Again, the purpose of this question is to ascertain if my solution is an acceptable one, and if it is not, what a proper one would be.
First the main class:
Next the menu mode class:
```
package Modes;
import JGameEngineX.JGameEngineX;
import JGameEngineX.JGam
I admit that the naming conventions in the following code may be slightly off-par, however, it makes sense to me as a free-spirited beginner who cares not for package.thousand_sub-packages.overly_long_class_name_and_full_essay.java.
Again, the purpose of this question is to ascertain if my solution is an acceptable one, and if it is not, what a proper one would be.
First the main class:
package TestingApp;
import JGameEngineX.JGameEngineX;
import Modes.Main_Game;
import Modes.Main_Menu;
import java.util.Random;
/**
* @author RlonRyan
* @name JBasicX_TestingApp
* @version 1.0.0
* @date Jan 9, 2012
* @info Powered by JBasicX
*
*/
public class JBasicX_TestingApp {
public static JGameEngineX instance;
public static final String[] options = {"Lambda Style!", "Javaaa!", "Spaaaaaace!", "Generic!", "Automated!", "Title goes here."};
public static void main(String args[]) {
if (instance != null) {
return;
}
String mode = args.length >= 1 ? args[0] : "windowed";
int fps = args.length >= 3 ? Integer.parseInt(args[2]) : 100;
int width = args.length >= 4 ? Integer.parseInt(args[3]) : 640;
int height = args.length >= 5 ? Integer.parseInt(args[4]) : 480;
instance = new JGameEngineX("JBasicX Testing Application: " + options[new Random().nextInt(options.length)], mode, fps, width, height);
instance.registerGameMode(new Main_Menu(instance));
instance.registerGameMode(new Main_Game(instance));
instance.init();
instance.start("main_menu");
}
}Next the menu mode class:
```
package Modes;
import JGameEngineX.JGameEngineX;
import JGameEngineX.JGam
Solution
Looks completely acceptable to me. If there is no reason to hold on to the lambdas in some other way, e.g. to flush or remove them, and they're not too big or complicated to distract from the current context, then I see this as much the preferred way to do it.
Short answer but, yeah, good question.
Short answer but, yeah, good question.
Context
StackExchange Code Review Q#48845, answer score: 3
Revisions (0)
No revisions yet.