No, there is nothing of the kind directly available. However, if you use a library with Tuple classes, you can mimic it by simply creating an interface
interface Foo<T> { void invoke(T t); }
(This interface is essentially the same as Consumer<T> .)
Then you could do, for example,
Foo<Tuple<String, Integer, Date, Long>> foo = new Foo<>() { ... }
For each number of parameters, a separate Tuple type is required. If you have a Tuple class for 4 parameters, but not one for 5, you can compress an additional parameter using the Pair class.
Foo<Tuple<String, Integer, Date, Pair<Long, BigDecimal>>> foo = ...
When nesting tuple types this way, you get an unlimited number of parameters. However, these workarounds are really ugly, and I would not use them.
Paul boddington
source share