How to make methods in beanshell?

I made a simple beanshell ide in android using edittext and button. When the button is pressed, it is called Interpreter.eval()and passed as a parameter edittext.getText().toString(). I want to know: how can I create a method in beanshell and run it?

This is the code I'm trying to execute in my beanshell ide:

import android.widget.Toast

int i=add(1, 5);
Toast.makeText(context, ""+i, 5000).show();

int add(int i, int j){
    return i+j;
}

But I get the following error:

Command not found: add ()

+5
source share
1 answer

You tried to move the definition of your function over its use, for example:

import android.widget.Toast

int add(int i, int j){
    return i+j;
}

int i=add(1, 5);
Toast.makeText(context, ""+i, 5000).show();

Does it really matter?

+8
source

All Articles