O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

The best of AltJava is Xtend

3.779 visualizações

Publicada em

#渋谷java

Publicada em: Software
  • Seja o primeiro a comentar

The best of AltJava is Xtend

  1. 1. The best of AltJava is Naoki Takezoe @takezoen BizReach, Inc #渋谷java
  2. 2. What's Xtend? ● Hosted by Eclipse Foundation ● Based on Xtext ● Similar syntax to Scala or Kotlin ● Compiled to Java source code (not class file) ● Eclipse and IntelliJ support
  3. 3. What's Xtend?
  4. 4. What's Xtend?
  5. 5. _人人人人人人_ > Java10!! <  ̄Y^Y^Y^Y^Y ̄
  6. 6. What's Xtend?
  7. 7. Tool support ● IDE Plugins ○ Eclipse ○ IntelliJ IDEA (not work with IntelliJ 2017.1.2?) ● Build tools ○ Maven ○ Gradle
  8. 8. Eclipse support You can install Xtend support from the update site.
  9. 9. About Xtext ● Framework for development of languages ● Define language using BNF like DSL ● Generate toolkit like parser or editor from it Language Definition Parser Compiler Linker Type checker Editor Generate
  10. 10. Xtext Summit ● In EclipseCon 2017 France ● June 20-21 (2days!!) ● One of the hottest projects in Eclipse.org
  11. 11. Language features
  12. 12. Basic syntax ● def / var / val ● () in method invocation is optional ● return and return type are optional ● null-safe call: myRef?.doStuff ● All exceptions are treated as runtime ● if, try, switch and block are expression (for and while are void, unfortunately)
  13. 13. Extension methods class HelloWorld { def static print(String s){ println(s) } def static void main(String[] args){ "Hello World".print() } }
  14. 14. Extension methods class StringExtensions { def print(String s){ ... } } class HelloWorld { static extension StringExtensions extensions = … def static void main(String[] args){ "Hello World".print() } } Import extension methods defined in other class
  15. 15. Lambda expressions def static void main(String[] args){ val list = Arrays.asList("Kotlin", "Java", "Xtend") Collections.sort(list) [ a, b | a.length - b.length ] println(list) } Translated to lambda
  16. 16. Dispatch methods def static dispatch printType(Number x) { "it's a number" } def static dispatch printType(Integer x) { "it's an int" } def static void main(String[] args){ println(10.printType) }
  17. 17. Switch expressions def length(Object x) { switch x { String case x.length > 0 : x.length List<?> : x.size default : -1 } } Type guard and case guard are available
  18. 18. Template expressions def someHTML(String content) ''' <html> <body> «content» </body> </html> ''' Three single quote! Embed variables as «...»
  19. 19. Active annotations (Macro) @Data class User { long userId String userName String email } Generate code triggered by annotation
  20. 20. Summary
  21. 21. Xtend... ● has simple and powerful syntax. ● has excellent Eclipse support. ● covers Web, GUI and Android. ● offers 100% Java interop.
  22. 22. Try http://www.eclipse.org/xtend/

×