Java Snippet function with parameters throwing a Syntax Error

I’m trying to write a simple function in Java that should have the correct syntax, but I’m getting a
syntax error on token “(”, ; expected

An example code is the following:

// system imports
import org.knime.base.node.jsnippet.expression.AbstractJSnippet;
import org.knime.base.node.jsnippet.expression.Abort;
import org.knime.base.node.jsnippet.expression.Cell;
import org.knime.base.node.jsnippet.expression.ColumnException;
import org.knime.base.node.jsnippet.expression.TypeException;
import static org.knime.base.node.jsnippet.expression.Type.*;
import java.util.Date;
import java.util.Calendar;
import org.w3c.dom.Document;

// Your custom imports:

// system variables
public class JSnippet extends AbstractJSnippet {

// Your custom variables:

// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:

public static int sumArrayElements(int[] arr) {
    int sum = 0;
    for (int i = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}

// expression end
}
}

Do you know how to solve it ?

Hi @alankohler920,

the expression start section is a method body (of the method snippet()) that is called for every row in the input table. Since you’re already in a method at that point you can’t define a method.

You should be able to define the method beforehand in the system variables section.

Kind regards
Marvin