Created
November 8, 2018 10:27
-
-
Save mcupak/1330f98c7b393d34510b6dff80027390 to your computer and use it in GitHub Desktop.
JShell transcript from the Writing clean code with Java session at VoxxedDays Bristol 2018.
This file contains 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
1+1 | |
int x = 1+1 | |
System.out.println(x) | |
Thread.sleep(2000) | |
/vars | |
/types | |
/list | |
/l | |
/help | |
Set<String> set = new HashSet<String>() | |
set.add("a") | |
set.add("b") | |
set.add("c") | |
Collections.unmodifiableSet(set) | |
List<Integer> list = List.of(1,2,3) | |
list.add(4) | |
list.getClass() | |
Map.ofEntries(entry(1, "hello")) | |
List.copyOf(list) | |
Set.copyOf(list) | |
/op readfile.jsh | |
/l readFile | |
/ed readFile | |
readFile("/tmp/hello.txt") | |
new FileInputStream("/tmp/hello.txt").transferTo(System.out) | |
/open myinterface.jsh | |
/l MyInterface | |
/op myclass.jsh | |
/l MyClass | |
/ed MyInterface | |
new MyClass().defaultMethod() | |
new MyClass().privateMethod() | |
IntStream.iterate(0, i -> i+2).filter(j -> j<100).forEach(System.out::println) | |
IntStream.iterate(0, i -> i+2).limit(50).forEach(System.out::println) | |
IntStream.iterate(0, i -> i+2).takeWhile(j -> j<100).forEach(System.out::println) | |
IntStream.iterate(0, i -> i<100, i -> i+2).forEach(System.out::println) | |
Stream.of(1) | |
Stream.of(null) | |
Stream.ofNullable(null) | |
Stream.ofNullable(null).count() | |
Stream.ofNullable(null).collect(toList()) | |
Stream.ofNullable(null).collect(toUnmodifiableList()) | |
Optional.empty() | |
Optional.of("something" | |
) | |
Optional.empty().isPresent() | |
Optional.empty().ifPresent(System.out::println) | |
Optional.empty().ifPresentOrElse(System.out::println, () -> System.out.println("empty")) | |
Optional.empty().orElse("empty") | |
Optional.empty().orElseGet(() -> "empty") | |
Optional.empty().orElseGet(() -> Optional.of("empty")) | |
Optional.empty().orElseThrow() | |
Optional.empty().stream().forEach(System.out::println) | |
Optional.of("something").stream().forEach(System.out::println) | |
Supplier<String> helloSupplier = new Supplier<String>() { public String get() { return "hello bristol"; }} | |
Supplier<String> helloSupplier = new Supplier<>() { public String get() { return "hello bristol"; }} | |
/v helloSupplier | |
var list = new ArrayList<String>() | |
/v list | |
var x | |
var x = null | |
var x = (Integer) null | |
var x=0, y=1; | |
int inc(int x) { return x+1; } | |
int inc(var x) { return x+1; } | |
var inc(int x) { return x+1; } | |
short x =1 | |
var x =1 | |
/v x | |
class MyClass { var x =1; } | |
var[] x = {1,2} | |
var x = {1,2} | |
var x = new int[]{1,2} | |
try {} catch (Exception ex) {} | |
try {} catch (var ex) {} | |
try { var x =1;} catch (Exception ex) {} | |
Supplier s = () -> "" | |
var s = () -> "" | |
Consumer c = x -> System.out.println(x) | |
Consumer c = (var x) -> System.out.println(x) | |
BiConsumer c = (var x, var y) -> System.out.println(x) | |
BiConsumer c = (var x, y) -> System.out.println(x) | |
BiConsumer c = (var x, Integer y) -> System.out.println(x) | |
Consumer c = System.out::println | |
var c = System.out::println | |
var list = new ArrayList<>() | |
/v list | |
var list = new ArrayList<>(Set.of(1)) | |
/v list | |
var x =new Object() { int a =1; int b =2;} | |
x.a | |
/v x | |
Object x =new Object() { int a =1; int b =2;} | |
x.a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment