Basically I'm trying to add a runnable class to a tasking threading class of my own which executes these tasks on a different thread, I need to pass the parameters to the runnable object, but I'm having trouble passing strings as the compiler tells:
"Local variable receiver defined in an enclosing scope must be final or effectively final"
String message = networkMessage.getString();
Game.getInstance().addGameTask(new Runnable() {
@Override
public void run() {
Game.getInstance().playerTalk(player.getId(), message);
}
});
I tried using Lambda with Runnable to do something as simpler as:
Runnable r = () -> Game.getInstance().playerTalk(player.getId(), mode, receiver, channelId, message);
But the compiler will say the same error.
In C# I would come up with something as simple as:
Game.AddGameTask(() => { Game.PlayerTalk(_player.Id, message, mode, receiver, channelId); });
What can I attempt to achieve something as simple as that? It's task is supposed to be for a game server, so I need to add these "tasks" to an external thread for better functioning and performance.
What is wrong?