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 annotation processors - Roma Android User Group #1


Published on

David Caroseli | Java Annotation Processors And Domain Model Objects

Spiegherò brevemente cos'è un Annotation Processor e come può essere usato per farci risparmiare molto tempo ed avere del codice altamente efficiente. Gli oggetti del modello di dominio sono solitamente delle classi Java con funzionalità standard che sono semplici quanto noiose da scrivere e da tenere aggiornate. I processori di annotazioni possono esserci utili per automatizzare questo processo ed avere del codice sempre aggiornato e non dover rinunciare all'efficienza.

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Java annotation processors - Roma Android User Group #1

  1. 1. + Davide Caroselli, CTO at Pubster Java Annotation Processors & Domain Model Objects
  2. 2. + Domain Model Objects Pub Deal PubsterLite Domain Model •  ID [long] •  Name [String] •  Address [String] •  Latitude [double] •  Longitude [double] •  ID [long] •  Name [String] •  Coins [int] •  Type [long]
  3. 3. + Coding… n  Getter methods n  Setter methods n  JSON serialization and deserialization methods n  Parcelable serialization and deserialization methods n  … FOR EACH DOMAIN MODEL CLASS !
  4. 4. + Java Reflection n  Easy to use n  Its behaviour can be customized n  It works! n  Bad performances n  Not ALL the code could be automatized (getter and setter) n  Could not be used for every task, or for very specific implementation logic PRO CONS
  5. 5. + Java Annotation Processor CODENAME: Automagically!
  6. 6. + Java Annotation Processor CODENAME: Automagically! n  Annotations n  “Mark” the code in a given point to attach a sort of meta- data that the Java Compiler or Runtime Environment can parse and use. n  Java Annotation Processor n  A processor that run at compile-time and could add brand new source files to the build. It can “read” the Annotations in the code.
  7. 7. Demo
  8. 8. + Want more? n Any model-level common logic methods (normalization, validation…) n SQLite serialization and deserialization methods n Maybe lazy load getter and setter ? n  Fetch objects when you need to!
  9. 9. Want EVEN more ?
  10. 10. + iOS or Windows Phone Domain Model Class