Adaptable Interface

[vc_row][vc_column width=”2/3″][vc_column_text el_class=”documentation”]Java objects implementing the interface provide a way to be adapted to an object that implements a different interface. The Adaptable interface can provide the adapted object itself within its adaptTo() method. It is highly suggested that implementations of the Adaptable interface use the service to provide an adapted object if a match is not found.

The easiest way to do this is to extend the abstract class and call the super.adaptTo method if a suitable, adapted, object was not found. See SlingAdaptable for examples.



<AdapterType> AdapterType adaptTo(Class<AdapterType> type);

type: The Class object to adapt to


An object that is an instance of the class specified in the type parameter. If not able to adapt to the requested type, null is returned.

Note: AdapterType is not an interface or class. It is a type parameter for the generic type, such as the conventional symbols, E, K, N, T, V.


public class MyAdaptable implements Adaptable {

private AdapterManager adapterManager;

     private Node node;

     public MyAdaptable(Node node, AdapterManager adapterManager) {
          this.adapterManager = adapterManager;
          this.node = node;
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
          if (type == Node.class) {
               return this.node;
          return adapterManager.getAdapter(this, type);

See Also


Generic Types

Adapter JavaDoc

GitHub: Package Trunk -[/vc_column_text][/vc_column][vc_column width=”1/3″][vc_widget_sidebar sidebar_id=”woocommerce”][/vc_column][/vc_row][vc_row][vc_column width=”1/2″][vc_column_text]Previous: Adapters: Apache Sling API Bundle[/vc_column_text][/vc_column][vc_column width=”1/2″][vc_column_text]

Next: AdapterManager Interface