> For the complete documentation index, see [llms.txt](https://proxetta.jodd.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://proxetta.jodd.org/wrapper.md).

# Wrapper

`WrapperProxetta` works differently than `ProxyProxetta`: instead of extending the target class, it creates new class that delegates call to target instance.

### WrapperProxetta overview

![](/files/-MUytg364gK0tS9ivmlb)

`WrapperProxetta` generates new class that delegates calls to target class instance. It is not enough to create a wrapper class and the instance - you must inject the target instead into it, too.

There are 3 ways how to build a wrapper.

#### Wrapper over class

Resulting object is custom type that implements all interfaces of the target. All target methods are wrapped.

#### Wrapper over class, casted to interface

Similar as above, except the resulting type implements one interface (provided by user). Still, all target methods are wrapped, even those that does not belong to the interface. They can be invoked using e.g. reflection.

#### Wrapper over interface

Resulting object has one interface, and only interface methods are wrapped.

### Example

Here is an example of how to create wrapper class and inject target instance into it.

```java
WrapperProxetta proxetta = Proxetta
    .wrapperProxetta()
    .withAspect(aspect);
WrapperProxettaFactory factory = proxetta
    .proxy()
    .setTarget(calc.getClass())
    .setTargetInterface(Calc.class);

Calc calc = factory.newInstance();
factory.injectTargetIntoWrapper(calc, calculatorObject);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://proxetta.jodd.org/wrapper.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
