0

Is it possible to write primitive function in ? Something like this:

void x() {
    System.out.printf("ok");
}

Like this in :

function x() {
    console.log('ok');
}
7
  • 1
    You mean a standalone function, as opposed to a method? Commented Oct 23, 2020 at 11:52
  • Add static to it? Or do you mean lambdas? Commented Oct 23, 2020 at 11:53
  • @khelwood yes, function without class. Commented Oct 23, 2020 at 11:53
  • Not really. You can put a static method inside a class. Or you can assign a lambda function to a local variable or a field. But it's still inside a class. Pretty much everything in Java is inside a class. Commented Oct 23, 2020 at 11:53
  • 1
    Each method needs to be defined in a class but methods can live without instances if they are static. What you want breaks the OOP concept of java. Commented Oct 23, 2020 at 11:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.