Package org.javagi.gobject
Class JavaClosure
java.lang.Object
org.javagi.base.ProxyInstance
org.gnome.gobject.Closure
org.javagi.gobject.JavaClosure
-
Nested Class Summary
Nested classes/interfaces inherited from class org.gnome.gobject.Closure
Closure.MarshalCallback -
Constructor Summary
ConstructorsConstructorDescriptionJavaClosure(@Nullable Object instance, Method method) Construct aClosurethat will invoke the provided Java method using reflection.JavaClosure(Object lambda) Construct aClosurethat will invoke the provided Java lambda using reflection.JavaClosure(Runnable callback) Construct aClosurefor a method or lambda that takes no parameters and returns void.JavaClosure(BooleanSupplier callback) Construct aClosurefor a method or lambda that takes no parameters and returns boolean. -
Method Summary
Modifier and TypeMethodDescriptionstatic MethodgetSingleMethod(Class<?> cls) Get the single abstract method (SAM) implementation of a class that implements a functional interface.Ignore the first parameter of the closure.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, writeNotifiersMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
JavaClosure
-
JavaClosure
Construct aClosurefor a method or lambda that takes no parameters and returns boolean.- Parameters:
callback- a callback with signatureboolean run()
-
JavaClosure
Construct aClosurethat will invoke the provided Java lambda using reflection. The Closure function arguments are read from the argument-Valuecontainers 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 aClosurethat will invoke the provided Java method using reflection. The Closure function arguments are read from the argument-Valuecontainers 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
-
ignoreFirstParameter
Ignore the first parameter of the closure. This is often the source of an event, a property binding, or something else that is not included in the Java API, so this option specifies to ignore it.- Returns:
- this JavaClosure
-
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- ifclsis not a functional interface
-