From c0bfd286882d3223bce7f74ce20793dfd32e32de Mon Sep 17 00:00:00 2001 From: GordonBGood Date: Tue, 22 Jan 2019 11:08:26 +0700 Subject: [PATCH] Add an example showing FFI of a static method with no parameters... The type signature to use when importing a method (static or instance) with no parameters was formerly not formally documents; This PR provides an example of how to do it. --- .../0-eta-user-guide/3-java-interop/2-java-ffi.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/0-user-guides/0-eta-user-guide/3-java-interop/2-java-ffi.md b/docs/0-user-guides/0-eta-user-guide/3-java-interop/2-java-ffi.md index e99a6359..9a27067c 100644 --- a/docs/0-user-guides/0-eta-user-guide/3-java-interop/2-java-ffi.md +++ b/docs/0-user-guides/0-eta-user-guide/3-java-interop/2-java-ffi.md @@ -86,6 +86,20 @@ foreign import java unsafe "@static java.io.File.createTempFile" createTempFile2 :: String -> String -> File ``` +### Example importing a static method with no arguments (use the same type of signature for instance methods with no parameters) + +``` eta +import Java + +foreign import java unsafe "@static java.lang.System.currentTimeMillis" + currentTimeMillis :: IO Int64 + +main :: IO () +main = do + now <- currentTimeMillis + print now +``` + ## Importing Constructors Let’s import the `File(String)` [constructor](https://docs.oracle.com/javase/7/docs/api/java/io/File.html#File(java.lang.String)) from the [java.io.File](https://docs.oracle.com/javase/7/docs/api/java/io/File.html) class.