Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 2.17 KB

README.md

File metadata and controls

50 lines (35 loc) · 2.17 KB

CI Javadocs Maven package

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 :)

How?

Some type token chicanery and good ol' cons for inspiration.

Why?

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

Usage?

Basically, Maven and GitHub Packages:

  1. Add https://maven.pkg.github.com/hanjos/genericcons as a repo in your pom.xml;
  2. Set up a personal access token in your settings.xml with package reading rights;
  3. Add the dependency in your pom.xml. The versions available can be seen here.
  4. You're good to go!

Of course, one can always download the code and mvn install...