From 3fffb7f3fd34f45cbcc4f006000e93507a7a65fd Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Tue, 22 Jan 2019 22:33:57 +0100 Subject: [PATCH] Add an example of a wrapper of a interface with several methods Close #561 --- .../3-java-interop/5-java-advanced-ffi.md | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/0-user-guides/0-eta-user-guide/3-java-interop/5-java-advanced-ffi.md b/docs/0-user-guides/0-eta-user-guide/3-java-interop/5-java-advanced-ffi.md index a12926e5..1d2cdbd0 100644 --- a/docs/0-user-guides/0-eta-user-guide/3-java-interop/5-java-advanced-ffi.md +++ b/docs/0-user-guides/0-eta-user-guide/3-java-interop/5-java-advanced-ffi.md @@ -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: @@ -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.