Skip to content

Instantly share code, notes, and snippets.

@mcupak
Created October 19, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcupak/fb78129b4751b36129ac933201f4aa67 to your computer and use it in GitHub Desktop.
Save mcupak/fb78129b4751b36129ac933201f4aa67 to your computer and use it in GitHub Desktop.
JShell transcript from the talk Pushing boundaries of types with modern Java at GeeCON Prague 2018.
1+1
int x = 1+1
System.out.println(x)
Thread.sleep(2000)
/vars
/methods
/types
int inc(int x) { return x+1; }
inc(4)
class MyClass { static void hello() {System.out.println("hello geecon"); } }
MyClass.hello()
/list
/l
/help
List<String> list = new ArrayList<String>()
new ArrayList<String>()
new ArrayList<Integer>()
$10.getClass()==$11.getClass()
$10.getClass()
class MyClass<T> { T a; }
new MyClass<String>().a
class MyClass<T> { static T a; }
<T> Collection<T> add(Collection<T> items, T item) { items.add(item); return items; }
add(new ArrayList<String>(), "a")
/v
/drop add
<T extends Number> Collection<T> add(Collection<T> items, T item) { items.add(item); return items; }
add(new ArrayList<String>(), "a")
add(new ArrayList<Integer>(), 1)
<T extends Number & Comparable> Collection<T> add(Collection<T> items, T item) { items.add(item); return items; }
add(new ArrayList<Integer>(), 1)
<T> Collection<? super T> add(Collection<? super T> items, T item) { items.add(item); return items; }
add(new ArrayList<Integer>(), 1)
List<String> list = new ArrayList<String>()
List<String> list = new ArrayList<>()
Consumer c = x -> System.out.println(x)
Collections.emptyList()
/v
List<String> list = Collections.emptyList()
/v list
void print(List<String> s) { System.out.println(s); }
print(Collections.emptyList())
print(Collections.<String>emptyList())
Supplier<String> helloSupplier = new Supplier<String>() { public String get() { return "hello geecon"; } }
helloSupplier.get()
Supplier<String> helloSupplier = new Supplier<>() { public String get() { return "hello geecon"; } }
int x = 0
var x = 0
/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
class MyClass { MyClass(var i) {}}
class MyClass { var x = 1; }
var var = 1
void var() {}
class var {}
interface var {}
var[] x = {1,2}
var x = {1,2}
var x = new int[]{1,2}
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)
/v c
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
List<Integer> list = List.of(1)
/v list
var x = list.get(0)
/v x
List<?> list2 = list
/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment