One of hundreds of answers available with our premium content service.
A: An adapter in Java is a design pattern in which you create a class "wrapper" around an object of one type so that it can be used as, and behave like, an object of another type. The adaptation of classes to the target interface is often done by composition rather than inheritance so that the adapter fully encapsulates the adapted class to maintain the integrity of both.
To enable a plain Java Person class to be used in a Swing application, you might create a SwingPerson adapter. The example below encapsulates a private Person instance in a JPanel with labelled text fields to represent the person's first and last name, with basic getters and setters for each. The extension of the JPanel class means that the adapter inherits all standard Swing Component functionality. The encapsulation of the Person class "adaptee" means that any special behaviour the Person class has does not have to be rewritten.
… full answer hidden
Premium members click below for full answer
What are adapters in Java?
We love social media, but we do not expect you to create yet another public outpost on the Web.