Package io.github.jwharm.javagi.gobject
Class JavaClosure
java.lang.Object
io.github.jwharm.javagi.base.ProxyInstance
org.gnome.gobject.Closure
io.github.jwharm.javagi.gobject.JavaClosure
-
Nested Class Summary
Nested classes/interfaces inherited from class org.gnome.gobject.Closure
Closure.MarshalCallback
-
Constructor Summary
ConstructorDescriptionJavaClosure
(Object lambda) Construct aClosure
that will invoke the provided Java lambda using reflection.JavaClosure
(Object instance, Method method) Construct aClosure
that will invoke the provided Java method using reflection.JavaClosure
(Runnable callback) Construct aClosure
for a method or lambda that takes no parameters and returns void.JavaClosure
(BooleanSupplier callback) Construct aClosure
for a method or lambda that takes no parameters and returns boolean. -
Method Summary
Modifier and TypeMethodDescriptionstatic Method
getSingleMethod
(Class<?> cls) Get the single abstract method (SAM) implementation of a class that implements a functional interface.Methods inherited from class org.gnome.gobject.Closure
addFinalizeNotifier, addInvalidateNotifier, addMarshalGuards, getMemoryLayout, getType, invalidate, invoke, object, overrideMarshal, readData, readNotifiers, ref, removeFinalizeNotifier, removeInvalidateNotifier, setMarshal, setMetaMarshal, simple, sink, unref, writeData, writeNotifiers
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
JavaClosure
-
JavaClosure
Construct aClosure
for a method or lambda that takes no parameters and returns boolean.- Parameters:
callback
- a callback with signatureboolean run()
-
JavaClosure
Construct aClosure
that will invoke the provided Java lambda using reflection. The Closure function arguments are read from the argument-Value
containers and passed to the lambda. The return value of the lambda is put in the Closure return-Value
.- Parameters:
lambda
- a lambda (instance of a functional interface)- Throws:
IllegalArgumentException
- if the lambda is not an instance of a functional interface
-
JavaClosure
Construct aClosure
that will invoke the provided Java method using reflection. The Closure function arguments are read from the argument-Value
containers and passed to the method. The return value of the method is put in the Closure return-Value
.- Parameters:
instance
- a class instance on which the provided method will be invoked. When the method is static, this parameter is ignored and and may benull
.method
- the method to invoke. SeeMethod.invoke(Object, Object...)
-
-
Method Details
-
getSingleMethod
Get the single abstract method (SAM) implementation of a class that implements a functional interface. A functional interface is an interface with exactly one abstract method.- Parameters:
cls
- a functional interface- Returns:
- the Method reference to the method that implements the SAM
- Throws:
IllegalArgumentException
- ifcls
is not a functional interface
-