Skip to content
Open
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
13 changes: 13 additions & 0 deletions content/md/articles/language/interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,19 @@ Syntax error (IllegalArgumentException) compiling . at (REPL:4:29).
More than one matching method found: submit
```

## Clojure Functions may act as Functional Interfaces

Clojure developers can [invoke Java methods taking Functional Interfaces by passing functions](https://clojure.org/reference/java_interop#functional_interfaces)
with matching arity.

Example:

``` clojure
(.list (io/as-file "/tmp") (fn [_ fname] (str/ends-with? fname ".csv")))

;; Note: Here we need a type hint to help the compiler distinguish between FilenameFilter and FileFilter
(.listFiles (io/file "/tmp") ^java.io.FilenameFilter (fn [_ fname] (str/ends-with? fname ".json")))
```

## gen-class and How to Implement Java Classes in Clojure

Expand Down