• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Adapter classes

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why there are no Adapter classes for Functional interfaces. Are Adapter classes there for marker interfaces?? Please reply.
 
Marshal
Posts: 69495
277
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only seen adapter classes for listeners for use on GUIs, where they are intended to provide skeleton implementations for listeners with multiple methods where the user only wants to provide a full implementation for one method. In which case they are of no use for functional interfaces. In fact they would be less than useless for functional interfaces; who wants to extend a class even as an anonymous class when they can write a λ instead? And how is anybody going to implement any methods in a marker interface? You will find a description of adapters in Cay Horstmann's big Core Java book, where he warns that a tiny spelling error can cause you to create a new method without the compiler noticing and yoo now have a subtle bug whereby the listener doesn't do anything. Horstmann omitted to say that annotating  the appropriate methods with @Override can cause that problem to become a compile time error.
 
Sushant Shindes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listeners are the things where Adapter classes come handy ofcourse listeners with multiple abstract methods.  But omitting annotation @Override when we use adapters may cause code to compile incorrectly. Am I correct please advice me as l have read above things in a Herbert Schildt Book. But I think in a book there is limitation of space to elaborate things.
 
Campbell Ritchie
Marshal
Posts: 69495
277
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sushant Shindes wrote:. . . omitting annotation @Override when we use adapters may cause code to compile incorrectly. Am I correct . . . .

Omitting @Override allows any method to comppile, even when there is an error so it doesn't override a superclass method. The idea behind @Override is to change failure to override a method correctly from a bug at runtime to a compile time error.
 
Sushant Shindes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it very clearly Thanks for your valuable response @ Marshal Campbell Ritchie.
 
Campbell Ritchie
Marshal
Posts: 69495
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sushant Shindes wrote:. . . Thanks . . .

That's a pleasure
 
Get out of my mind! Look! A tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic