Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add an example of a wrapper of a interface with several methods #938

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Let’s try to wrap the [java.util.function.Function](https://docs.oracle.com/ja



The import would look like so:
The import would be like this:



Expand All @@ -191,6 +191,27 @@ foreign import java unsafe "@wrapper apply"
=> (t -> Java (Function t r) r) -> Function t r
```

### Example wrapping a interface with several methods

When the interface or abstract class has various abstract methods we must implement all of them with the wrapper.

To wrap this java interface:

```java
public interface SomeInterface {
String method1(int i);
double method2(int i, int j);
}
```

We should implement this eta wrapper:

```eta
foreign import java unsafe "@wrapper method1,method2" :: (Int -> SomeInterface JString) -- method1
-> (Int -> Int -> SomeInterface JDouble) -- method2
-> SomeInterface
```

## Next Section

In the next section, we will look at how to add Java dependencies to our Eta code.