This Is Not Your Father's Java

11,239 views
11,141 views

Published on

A presentation about creative API Design and language feature emulation with Java

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,239
On SlideShare
0
From Embeds
0
Number of Embeds
59
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

This Is Not Your Father's Java

  1. 1. This is not your father’s JavaSven Efftinge - itemis
  2. 2. 5 Missing FeaturesCollection LiteralsObject LiteralsClosuresPropertiesMultiline Strings
  3. 3. Collection LiteralsList<String> names = new ArrayList<String>();names.add(“foo”);names.add(“bar”);names.add(“baz”);
  4. 4. Collection LiteralsList<String> names = new ArrayList<>();names.add(“foo”);names.add(“bar”);names.add(“baz”);
  5. 5. Collection LiteralsnewArrayList(“foo”, “bar”, “baz”) Static imports, generified method and var-args! Do you already use Google Guava?
  6. 6. Object LiteralsReadable data constructionJava Devs usually flee to some external format,such as XML or JSON.
  7. 7. Object Literals Java enforces imperative style.Person p = new Person();p.setFirstName("Hans");p.setLastName("Albers");Address address = new Address();address.setStreet("Am Germaniahafen 1");address.setCity("Kiel");p.setAddress(address);
  8. 8. Object LiteralsPerson p = new Person() {{ firstName = "Hans"; lastName = "Albers"; address = new Address() {{ street = "Am Germaniahafen 1"; city = "Kiel"; }};}};
  9. 9. Object LiteralsPerson p = new Person() {{ firstName = "Hans"; lastName = "Albers"; address = new Address() {{ street = "Am Germaniahafen 1"; city = "Kiel"; }};}}; anonymous classes
  10. 10. Object LiteralsPerson p = new Person() {{ firstName = "Hans"; lastName = "Albers"; address = new Address() {{ street = "Am Germaniahafen 1"; city = "Kiel"; }};}}; Initializer
  11. 11. No Closures My friends’ names in a comma separated string.List<Person> myFriends = ...StringBuilder sb = new StringBuilder();for (Person person : myFriends) { sb.append(person.getName()) .append(“, “);}String result = sb.toString().substring(0, sb.length()-2);
  12. 12. How about this?List<Person> myFriends = ...String names = joinFrom(myFriends).getName(); generics and proxies!LambdaJ - http://code.google.com/p/lambdaj/
  13. 13. Closures in Java 8List<Person> myFriends = ...List<String> names = myFriends .map(#{ p -> p.getName(); });
  14. 14. Propertiesclass Person { public String firstName;}Person p = ....p.firstName = “Horst”;
  15. 15. Properties class Person { public String firstName; public void setFirstName(String s) { firstName = process(s); } } Person p = .... p.firstName = “Horst”;Byte code manipulation during class loading!
  16. 16. Multiline Stringspublic static void main(String[] args){ System.out.println($(/* Wow, we finally have multiline strings in Java! HOOO! */));} Source code & stack trace information
  17. 17. Beyond JavaOther JVM-Languages Eclipse XtendDSLs Eclipse Xtext 2.

×