How to crash javac (jdk8) for free

This simple snippet can cause javac (from the JDK 8) to crash : public class TestExtendConsumer { @FunctionalInterface public interface NumberConsumer< E extends Number> extends java.util.function.Consumer< E>{void accept(E number);} private static < E extends Number> void extend(E number) { System.out.println(number); } public static void main(String[] args) { NumberConsumer numberConsumer = TestExtendConsumer::extend; numberConsumer.accept(1); } } Impressive.… Read More »

Convert List(a,b,c,d) into Map(a->b,c->d) in Java 8

Let input be a List of String, you want it to become Map<String, String> where even elements are the keys, and odd elements are the values. Works only when key elements are unique. Map<String, String> mappedValues = Function.identity(), input::indexOf)).entrySet().stream().collect(Collectors.toMap( entry -> {return entry.getKey();}, entry -> {return entry.getValue() == input.size() − 1 ? −1 :… Read More »