# Are multi-method solutions allowed in Java?

I recently joined this community as a Java golfer, and I haven't been able to find a definitive consensus on acceptable solution formats for Java.

From what I gather, the following are allowed (please correct if consensus is otherwise):

• full program (class definition with main method)
• full method (modifiers, signature, body)
• lambda expression

What I'm wondering about is whether a multi-method solution is acceptable.

# Description

Such a solution would consist of program text defining two or more methods as they would appear in a class definition, a choice of one such method as an entry point to the program (which would take input and produce output according to standard rules), and, optionally, a class name. To clarify: a multi-method solution would not include fields, initializers, or class definitions; only methods.

# Execution

These solutions would be tested by inserting the program text into an empty definition of a public class (as named by the author, if applicable) and then invoking, from a class within the same package, the entry method on an instance of the class produced by the default constructor or on the class itself if the method is static (author's choice).

# Rationale

It's easy to imagine this being a desirable format for complex solutions. It permits subroutines more cheaply than a lambda or method solution (where class definitions or functional interface declarations would be required), and it is preferable to a full program solution because I/O can be done flexibly through method parameters and return values and class boilerplate is eliminated.

If this question gets enough activity, I assume consensus will be decided by answer score. Answers may then be affirmative, negative, or affirmative with conditions/exceptions. If this has already been addressed, someone can refer to that discussion and close this one.

• People do this all the time – Pavel Aug 10 '17 at 2:12

# You're allowed to define just methods

We accept the definition of a single method as a code-golf answer, such:

public void f(int a, int b, int c){System.out.println("Blah blah");}


And it should be equally acceptable to define many methods.

public int c(int a, int b){return a+b;}
public void f(int a, int b){System.out.println(c(a,b))}


As long as you're not assuming anything else about the program, EG. A Class Name, Imports, etc.

• I see. Perhaps I didn't need to write such an elaborate question then! – Jakob Aug 10 '17 at 2:01
• Always good to ask, also, don't fret asking these questions over on the nineteenth byte, our chat room – ATaco Aug 10 '17 at 2:02
• But what about Java's lambdas? – Okx Aug 10 '17 at 18:45
• @Okx Java lambdas are allowed, but there is some debate about whether or not type signatures need to be included/counted. – Mego Aug 10 '17 at 20:47