# Documentation for gololang.Adapters

This module defines an AdapterFabric helper.

## Structs

### adapter¶

##### Members

- `definition`

## Augmentations

### gololang.Adapters.types.adapter¶

Adapter augmentations.

#### extends(this, className)¶

Specifies the name of the parent class (`java.lang.Object` by default).

- parameter: parent class name
- returns the adapter.

Usage:

    let arrayListAdapter = Adapter()
      : extends("java.util.ArrayList")

#### implements(this, methodName, closure)¶

Provides a method implementation

- parameters: a method name, an implementation function
- returns the adapter.

Usage:

    let result = array[1,2,3]

    let runnerAdapter = Adapter()
      : interfaces(["java.io.Serializable", "java.lang.Runnable"])
      : implements("run", |this| {
          for (var i = 0, i < result: length(), i = i + 1) {
            result: set(i, result: get(i) + 10)
          }
        })

#### interfaces(this, interfacesTuple)¶

Defines interface(s) for the Adapter:

- parameter(s): a tuple of strings,
- returns the adapter.

Usage:

    let runnerAdapter = Adapter()
      : interfaces(["java.io.Serializable", "java.lang.Runnable"])

#### maker(this)¶

Returns an instance based on a configuration (see also `adapter: definition()`).

#### newInstance(this)¶

Returns an instance of the adapted Java class.

Usage:

    let result = array[1,2,3]

    let runnerAdapter = Adapter()
      : interfaces(["java.io.Serializable", "java.lang.Runnable"])
      : implements("run", |this| {
          for (var i = 0, i < result: length(), i = i + 1) {
            result: set(i, result: get(i) + 10)
          }
        })

    let runner = runnerAdapter: newInstance()

    runner: run()

#### newInstance(this, args...)¶

Returns an instance of the adapted Java class.

The parameters are the parameters of the base class constructor.

#### overrides(this, methodName, closure)¶

Provides a method override.

- parameters: method name and an implementation function
- returns the adapter.

Usage:

    let objectAdapter = Adapter()
      : overrides("toString", |super, this| -> ">>> " + super(this))

    println(objectAdapter: newInstance(): toString())

This prints something like: `>>> $Golo$Adapter$0@2aaf7cc2`.

## Functions

### Adapter()¶

Adapter constructor.