Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Java 8: le nuove-interfacce di Ezio Sperduto

1 576 vues

Publié le

Le interfacce di Java 8 sono molto diverse da quelle delle versioni precedenti. Vediamo in che modo.

Publié dans : Logiciels
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Java 8: le nuove-interfacce di Ezio Sperduto

  1. 1. Java  8   le  nuove  interfacce   Jug  Roma   ezio  sperduto  
  2. 2. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma   novità  introdo6e  da  Java  8     >    default  methods   >    metodi  sta:ci    
  3. 3. Jug  Roma   le  interfacce  pre  –  Java  8     >  contra6o  tra  programmatori                    (chi  crea  una  classe  e  chi  la  usa)     >  :po  astra4o     >  polimorfismo  di  :po    (ereditarietà  mul:pla,  classica  domanda  da  colloquio)     Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto  
  4. 4. Jug  Roma   le  interfacce  pre  –  Java  8     Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   permesso   vietato   proto:pi  metodi   implementazioni   costan:   variabili   solo  membri  pubblici   costru6ori  
  5. 5. Jug  Roma   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   default  methods:  implementazione  di   default  (comportamento),  presente  già   nell’interfaccia   interface Collection{ default void sort(Comparator c){ // ordina etc. } … }
  6. 6. Jug  Roma   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   language  designer   library  designer   sw  designer  
  7. 7. Jug  Roma   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   interfaccia  di  libreria   implementazione  programmatore   implementa  m.astra6o  1   m.astra6o  2   m.concreto  1   m.concreto  2   Ver.1  
  8. 8. Jug  Roma   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   interfaccia  di  libreria   implementazione  programmatore   implementa  m.astra6o  1   m.astra6o  2   m.concreto  1   m.concreto  2   Ver.1   interfaccia  di  libreria   implementazione  programmatore   implementa  m.astra6o  1   m.astra6o  2   m.concreto  1   m.concreto  2   Ver.2   m.astra6o  NEW   ?????????????   Il  programmatore  deve  modificare  la  sua  implementazione  per  poter  usare   la  nuova  libreria  (anche  senza  aggiungere  valore  al  suo  so8ware)    
  9. 9. Jug  Roma   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   interfaccia  di  libreria   implementazione  programmatore   implementa  m.astra6o  1   m.astra6o  2   m.concreto  1   m.concreto  2   Ver.1   interfaccia  di  libreria   implementazione  programmatore   implementa  m.astra6o  1   m.astra6o  2   m.concreto  1   m.concreto  2   Ver.2   default   method   m.default  NEW   Il  programmatore  beneficia  dell’implementazione  di  default  senza  alcuna  modifica   m.default  NEW  
  10. 10. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma    Kinds  Of  Compa5bility     ü  source  compa:bility          (compilazione  priva  di  errori)     ü  binary  compa:bility          (linking  privo  di  errori)     ü  behavioral  compa:bility          (escecuzione  priva  di  errori  logici)    
  11. 11. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma    Kinds  Of  Compa5bility     ü  source  compa:bility    NO      (compilazione  priva  di  errori)     ü  binary  compa:bility    OK      (linking  privo  di  errori)     ü  behavioral  compa:bility      ?    (escecuzione  priva  di  errori  logici)     Exception in thread "main" java.lang.AbstractMethodError error: Ellipse is not abstract and does not override abstract method setRelativeSize(int,int) in Ridimensionabile  
  12. 12. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       “Default methods are a new feature added in Java 8 to help evolve APIs in a compatible way”   default void setRelativeSize(int lFatt, int hFatt){ int newLarghezza = getLarghezza() / lFatt; int newAltezza = getAltezza() / hFatt; setAbsoluteSize(newLarghezza,newAltezza); }  
  13. 13. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       interfaces  VS  abstract  classes    sono  diventate  la  stessa  cosa?      SI  e  NI!   1. ereditarietà  (singola/mul:pla)   2. la  classe  astra6a  definisce  lo  STATO      -­‐  campi  definiscono  la  situazione  iniziale    -­‐  metodi  d’istanza  definiscono  comportamento  su  stato*    -­‐  costru4ori  definiscono  l’inizializzazione  dell’istanza**   *  dunque  i  default  method  non  sono  veri  e  propri  metodi  d’istanza?     **  costru6ori  si,  istanziazione  no  
  14. 14. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   Cosa  stampa?  interface A{ default void hello(){ System.out.println(“sono A”); } } interface B{ default void hello(){ System.out.println(“sono B”); } } class C implements A,B{ public static void main(String...args){ new C().hello(); } }
  15. 15. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   1.  la  classe  vince  sempre   un  metodo  dichiarato  in  classe/superclasse  ha  priorità  su  qualunque  default  method     2.  la  sub-­‐interfaccia  vince  sulla  super-­‐interfaccia   ha  priorità  il  default  method  più  specifico     (se  il  default  method  è  definito  in  A  e  B  con  la  stessa  firma,  e  B  estende  A,     il  metodo  scelto  sarà  sempre  quello  di  B)     3.  negli  altri  casi:  errore  del  compilatore!    se  non  ci  troviamo  in  1.  o  2.  abbiamo  un  ambiguità    (possiamo  evitarla  o  risolverla  manualmente*)  
  16. 16. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   // stesse interfacce A e B di prima public class D implements A{ } public class C extends D implements A,B{ public static void main(String...args){ new C().hello(); } } Cosa  stampa?   A   +  void  hello()   B   +  void  hello()   D   C  
  17. 17. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   Cosa  stampa?     La  regola  1.  indica  priorità  al  metodo  della  classe.  Ma  non  ci   sono  metodi  “dichiara:”  nella  classe  (non  c’è  overriding)     La  regola  2.  indica  che  ha  priorità  il  metodo  “più  specifico”     Dunque  stamperà  “sono  B”      
  18. 18. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   // stesse interfacce A e B di prima public class C implements A,B{ public static void main(String...args){ new C().hello(); } } Cosa  stampa?   A   +  void  hello()   B   +  void  hello()   C  
  19. 19. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules   Cosa  stampa?     Si  segue  la  regola  3.  (errore),  come  scavalcarlo?     Risposta:  override  nella  classe,  esplicitando  il  default   method  preferito     // stesse interfacce A e B di prima public class C implements A,B{ . . . void hello(){ B.super.hello(); } }
  20. 20. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules:  Diamond  Problem   A   +  void  hello()   B   D   C  
  21. 21. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules:  Diamond  Problem   interface A{ default void hello(){ System.out.println("sono A"); } } interface B extends A{} interface C extends A{} class D implements B,C{ public static void main(String...a){ new D().hello(); } Cosa  stampa?  
  22. 22. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules:  Diamond  Problem   interface A{ default void hello(){ System.out.println("sono A"); } } interface B extends A{} interface C extends A{} class D implements B,C{ public static void main(String...a){ new D().hello(); } Cosa  stampa?   Unico  metodo  a  disposizione  (default).     Non  ci  sono  ambiguità:  stampa  “sono  A”.     In  C++:  caso  più  complesso,  ereditarietà   mul:pla.  Doppia  copia  del  metodo  e   disambiguazione.  
  23. 23. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules:  Diamond  Problem  (v.2)   interface A{ default void hello(){ System.out.println("sono A"); } } interface B extends A{ void hello(); } interface C extends A{} class D implements B,C{ public static void main(String...a){ new D().hello(); } Cosa  stampa?  
  24. 24. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Resolu5on  Rules:  Diamond  Problem  (v.2)   interface A{ default void hello(){ System.out.println("sono A"); } } interface B extends A{ void hello(); } interface C extends A{} class D implements B,C{ public static void main(String...a){ new D().hello(); } Cosa  stampa?   Compe:zione  tra  metodo  default  e  metodo   astra6o.       Regola  2.  il  metodo  più  specifico  ha  priorità.   Il  metodo  astra6o  è  un  override  del  default.     Dunque  errore:  il  compilatore  chiederà   ridefinizione  in  D!  
  25. 25. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Default  Method:  usage  paDerns   >  opQonal  method    forzatura  nell’implementazione  di  metodo,  boilerplate  code    (lancio  un  eccezione  su  metodo  non  implementato)     >  ereditarietà  mulQpla  di  comportamento    ereditando  da  più  interfacce,  eredi:amo  più  default  method    -­‐  proge6azione  di  interfacce  minimiali    -­‐  composizione  di  interfacce  ortogonali  
  26. 26. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Nuove  Interfacce:  metodi  sta5ci   Pre  Java  8:    -­‐  creare  interfaccia  e  classe  accompagnatrice    (interfaccia  Collection  classe  Collections)   Con  Java  8:    -­‐  i  metodi  di  u:lità  comune  sono  incorpora:      nell’interfaccia  stessa,  si  sviluppa  solo  1  :po    (le  classi  precedentemente  sviluppate  sono  mantenute    per  retrocompa5bilità)  
  27. 27. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma       Esempi  reali   interface Collection<E>{ . . . default void sort(Comparator<? super E> c){ Collections.sort(this, c); } } interface Comparator<T>{ . . . static <T extends Comparable<? super T>>  Comparator<T> naturalOrder() { . . . } } List<Integer> numbers=Arrays.asList(0,1,1,2,3,5,8,13); numbers.sort(Comparator.naturalOrder()); maggiore  riflessività!  OOP   (Comparator  esempio  emblema5co)  
  28. 28. Jug  Roma   Riferimen:   Oracle   The  Java  Tutorials   Java  8  in  AcQon     Urma,  Fusco,  MycroO   (Manning)   Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto  
  29. 29. Java  8:  le  nuove  interfacce  -­‐  ezio  sperduto   Jug  Roma   Grazie  per  l’a6enzione!                          Domande?   Con:nua  con  .  .  .   “Java  8:  λ-­‐expression  e  programmazione  funzionale”  

×