Last active
March 21, 2018 07:59
-
-
Save bufferings/a07735229b57444374b83b3789be76be to your computer and use it in GitHub Desktop.
JShell で Effectively Final 遊び
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collections; | |
import java.util.List; | |
import java.util.stream.Stream; | |
/** | |
* こんなつぶやきを見かけたので、debugオプションつけて雰囲気見てみたお話。 | |
* https://twitter.com/mike_neck/status/976358507011178496 | |
* | |
* jshell> var list = List.of("foo", "bar") | |
* list ==> [foo, bar] | |
* | |
* jshell> Stream.of("baz").forEach(s -> list = Collections.singletonList(s)) | |
* | |
* jshell> list | |
* list ==> [baz] | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println($JShell$12.do_it$()); | |
System.out.println($JShell$17.do_it$()); | |
System.out.println($JShell$21.do_it$()); | |
} | |
} | |
class $JShell$12 { | |
public static List<String> list; | |
public static Object do_it$() { | |
List<String> list_ = | |
List.of("foo", "bar"); | |
return list = list_; | |
} | |
} | |
class $JShell$17 { | |
public static Object do_it$() { | |
Stream.of("baz").forEach(s -> $JShell$12.list = Collections.singletonList(s)); | |
return null; | |
} | |
} | |
class $JShell$21 { | |
public static Object do_it$() { | |
return $JShell$12.list; | |
} | |
} |
Author
bufferings
commented
Mar 21, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment