Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java Annotations Are Evil

636 views

Published on

JPoint 2017; Moscow, Russia; 8 April 2017; video is here: https://www.youtube.com/watch?v=20QBvrHq6TA

Published in: Technology
  • Be the first to comment

Java Annotations Are Evil

  1. 1. /24@yegor256 1 Аннотации — это зло Yegor Bugayenko Annotations Are Evil
  2. 2. /24@yegor256 2 “Егор в своем стиле: все гондурасы, а я д’Артаньян.” Д’Артаньян и три мушкетёра (1978)
  3. 3. /24@yegor256 3 “Попал как будто на выступление лидера какой-то секты.” The Evil Cult (1993)
  4. 4. /24@yegor256 4 “Автор — маньяк.” The Silence of the Lambs (1991)
  5. 5. /24@yegor256 5 1000+ takes.org 14000+ jcabi.com rultor.com jare.io since
 1988 2007 250+
  6. 6. /24@yegor256 6 since 2014
  7. 7. /24@yegor256 7 Compiler: @Override, @Deprecated, @SuppressWarning DI: @Inject, @Singleton, etc. Serialization: @XmlElement, etc. Validation: @NotNull, etc. Behavior: @GET, @Transaction AOP: @RetryOnFailure, @Cacheable Unit testing: @Test, @Before, @Rule, etc. Lombok: @ToString, @EqualsAndHashCode, etc. Something else?…
  8. 8. /24@yegor256 8 class Page { @GET String index() { return “Hello, world!”; } }
  9. 9. /24@yegor256 9 class Page { String index(Request request) { if (request.method().equals(“GET”)) { return “Hello, world!”; } return “Method not allowed”; } }
  10. 10. /24@yegor256 10 class Page { @GET String index() { return “Hello, world!”; } } class Dispatcher { String dispatch(Page page, Request request) { if (request.method().equals(“GET”) && page.getClass().getMethod(“index”) .isAnnotationPresent(GET.class)) { return page.index(); } return “Method not allowed”; } }
  11. 11. /24@yegor256 11 Page Dispatcher
  12. 12. /24@yegor256 12 Page Dispatcher 1 upside down
  13. 13. /24@yegor256 13 Page Dispatcher 2 unclear dependencies ???
  14. 14. /24@yegor256 14 —Ты BeanPostProcessor видишь? —Нет. —А он есть! ДМБ (2000)
  15. 15. /24@yegor256 15 Page 3 no encapsulation Data
  16. 16. /24@yegor256 16 HelloPage GETPage
  17. 17. /24@yegor256 17 class HelloPage implements Page { @Override String index(Request request) { return “200 Hello, world!”; } } class GETPage implements Page { private final Page page; @Override String index(Request request) { if (request.method().equals(“GET”)) { return page.index(); } return “Method not allowed”; } }
  18. 18. /24@yegor256 18 procedural
  19. 19. /24@yegor256 19 object-oriented
  20. 20. /24@yegor256 20 Compiler: @Override, @Deprecated, @SuppressWarning DI: @Inject, @Singleton, etc. Serialization: @XmlElement, etc. Validation: @NotNull, etc. Behavior: @GET, @Transaction AOP: @RetryOnFailure, @Cacheable Unit testing: @Test, @Before, @Rule, etc. Lombok: @ToString, @EqualsAndHashCode, etc.
  21. 21. /24@yegor256 21
  22. 22. /24@yegor256 22 Can I see the code?Можно ли посмотреть код?
  23. 23. /24@yegor256 23 The Shining (1980)
  24. 24. /24@yegor256 24 yegor256.com

×