Is there an interface from the JDK that looks something like this:
public interface Callback<T> {
public void process(T t);
}
The requirement is to implement a callback that runs code, but doesn't return anything.
I could write my own (by simply using the example code here), but I'd like to use an existing wheel if one exists, rather that reinventing one.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases. A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate the concept.
Another way is to create a generic class that implements the generic interface. The class definition uses the same formal type parameters twice – one after the class name and another after the interface name it implements. Consider the following codes. They use <U> twice in the two locations. 3.
generic class All instances of a generic class have the same run-time class, regardless of their actual type parameters. A class generic has the same behavior for all of its possible type parameters; "...
Generics enable non-primitive types (classes and interfaces) to be parameters when defining: and methods. Class was generified in release 1.5. The type of a class literal is no longer simply Class, but Class<T>. For example: and Integer.class is of type Class<Integer>. JPA - How to define a @One-to-Many relationship ? More ... Why ?
So you need something like
interface Foo<T>
bar(T)
Only 3 interfaces in JDK are like that
java.nio.file.DirectoryStream$Filter<T>
boolean accept(T entry) throws IOException;
java.lang.Comparable<T>
int compareTo(T o);
javax.xml.ws.Provider<T>
T invoke(T request);
Obviously you won't like them.
Async IO has a callback interface, but it's a bit more complicated:
java.nio.channels.CompletionHandler<V,A>
void completed(V result, A attachment);
void failed(Throwable exc, A attachment);
No, I don't believe there's such an interface currently. There's currently slated to be such an interface, called Block
(with an apply
method, I think), in JDK 8... though the name could well change between now and then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With