Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export of my JShell session from the Local variable type inference - Will it compile? talk at Devoxx Ukraine 2019.
var x = "hello"
/v x
var list = new ArrayList<String>()
/v list
int x
var x
var x = null
var x = (Integer) null
int x=0, y=0
var x=0, y=0
int inc(int x) { return x+1; }
int inc(var x) { return x+1; }
var inc(int x) { return x+1; }
for (var i=0; i<100; i++) {}
for (var i : list) {}
short x = 1
var x = 1
/v x
var x = 0x12345678
/v x
var x = 0x123456789
var x = 0x123456789l
/v x
class MyClass { var x = 1; }
var var = 1
void var() {}
class var {}
class Var {}
enum MyEnum { var }
int[] x = {1,2}
var[] x = {1,2}
var x = {1,2}
var x = new int[]{1,2}
try {} catch (Exception ex) {}
try { var x = 1; } catch (Exception ex) {}
try {} catch (var 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 list = new ArrayList()
/v list
var list1 = new ArrayList<Integer>()
/v list1
list1.add(1)
var x = list1.get(0)
/v x
list1.add(x)
/v list
/v list1
List<?> list2 = list1
/v list2
var x = list2.get(0)
list2.add(x)
/v x
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
<T extends Number & Comparable> T makeIntersectionType() { return null; }
var x = makeIntersectionType()
/v x
/env
int x = 0
switch (x) { case 0 -> 0; default -> 1; }
switch (x) { case 0,1 -> 0; default -> 1; }
var y = switch (x) { case 0,1 -> 0; default -> 1; }
/v y
var y = switch (x) { case 0,1 -> 0; default -> "hello"; }
/v y
var y = (x==0) ? 0 : "hello"
/v y
var y = (x==0) ? 0 : null
/v y
var y = (x==0) ? null : null
switch (x) { default -> System.out.println("hello"); }
var y = switch (x) { default -> System.out.println("hello"); }
var y = switch (x) { default -> { System.out.println("hello"); yield "hello"; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment