Who said Java generics can't accept an open-ended number of type variables? Just write something like
Fn<?, ?> f = new Fn<Integer, C<String, C<String, String>>>() {
public Integer execute(Object... objects) {
List<? extends Type> types = Types.fromSuperclass(this.getClass(), 1);
if(! Types.check(types, Arrays.asList(objects))) { // the given objects don't match!
return -1;
}
String a = (String) objects[0];
String b = (String) objects[1];
String c = (String) objects[2];
return Math.max(a.length(), b.length(), c.length());
}
};
Hey, I never said the solution was pretty. Or useful :)
Some type token chicanery and good ol' cons for inspiration.
It occurred to me one day, and I haven't contributed to Java's grand tradition of gross overengineering for quite some time, so there you go :P
Basically, Maven and GitHub Packages:
- Add https://maven.pkg.github.com/hanjos/genericcons as a repo in your
pom.xml
; - Set up a personal access token in your
settings.xml
with package reading rights; - Add the dependency in your
pom.xml
. The versions available can be seen here. - You're good to go!
Of course, one can always download the code and mvn install
...