Is there a way to "run / debug selected code" with given parameter values in eclipse?
No, Eclipse needs a regular method mainor method @Testas an entry point.
When I want to perform a “one” mini-test, what I usually do is
class YourClass {
private int specialAdd (int a, int b) {
if(a < 100) {
return 100 * a + b;
} else {
return a + b;
}
public static void main(String[] args) {
System.out.println(new YourClass().specialAdd(10, 100));
}
}
( ) . (Pro tip: main Ctrl + Space, )
JDK 9 jshell :
$ ./jshell
| Welcome to JShell -- Version 1.9.0-internal
| Type /help for help
-> int specialAdd(int a, int b) {
>> if (a < 100) {
>> return 100 * a + b;
>> } else {
>> return a + b;
>> }
>> }
| Added method specialAdd(int,int)
-> specialAdd(10, 5);
| Expression value is: 1005
| assigned to temporary variable $2 of type int