Skip to content

Commit

Permalink
Add an example of a wrapper of a interface with several methods
Browse files Browse the repository at this point in the history
Close #561
  • Loading branch information
jneira authored and rahulmutt committed Jan 23, 2019
1 parent 270c871 commit 76388d5
Showing 1 changed file with 22 additions and 1 deletion.
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.

0 comments on commit 76388d5

Please sign in to comment.