I'm playing with the JShell and trying to convert a variable to its original form. To do that, I reset everything in the REPL using /r
, then I imported java.util.*
and created a list:
-> import java.util.*;
-> List<String> l = new ArrayList<>(Arrays.asList("a", "b"));
| Modified variable l of type List<String> with initial value [a, b]
Now I'm trying to convert the lists values to upper case, so I'm doing:
-> l.replaceAll(String::toUpperCase)
-> l
| Variable l of type List<String> has value [A, B]
Listing the executed source I've typed using /list
(or /l
) shows:
-> /l
1 : List<String> l = new ArrayList<>(Arrays.asList("a", "b"));
2 : l.replaceAll(String::toUpperCase)
3 : l
Now when I try to reset the list to stage 1 (before changing its values), I'm getting the import
statement:
-> /1
import java.util.*;
Does anyone know why this happens? I tried the same without the import
statement, but I'm getting the same result (I assume this is because it's getting imported explicitly).
I've just notice that if I write /l all
I get:
-> /l all
s1 : import java.util.*;
s2 : import java.io.*;
s3 : import java.math.*;
s4 : import java.net.*;
s5 : import java.util.concurrent.*;
s6 : import java.util.prefs.*;
s7 : import java.util.regex.*;
s8 : void printf(String format, Object... args) { System.out.printf(format, args); }
1 : String a = "a";
2 : a = "b"
I don't know why /1
executes the first import
statement and not first the string assignment. Also it's really weird that even if import java.util.*;
is there, s5
is import java.util.concurrent.*;
(which is clearly redundant).