====== Java Generics ====== ===== - Basics ===== * https://nofluffjuststuff.com/magazine/2016/09/time_to_really_learn_generics_a_java_8_perspective * https://softwareengineering.stackexchange.com/questions/227918/java-use-polymorphism-or-bounded-type-parameters * ===== - Interfaces ===== * https://marcin-chwedczuk.github.io/generics-in-java Sometimes Java compiler must create synthetic methods (in this case called bridge methods) to make overriding work with generic types. For example: interface TestInterface { void consume(T value); } class TestClass implements TestInterface { @Override public void consume(Integer value) { System.out.println(value); } } after type erasure becomes: interface TestInterface { void consume(Object value); } class TestClass implements TestInterface { public void consume(Integer value) { System.out.println(value); } } and we can see that TestClass no longer overrides consume method from TestInterface. To solve this problem compiler adds following method to TestClass: class TestClass implements TestInterface { // bridge method added by compiler: @Override public void consume(Object value) { this.consume((Integer)value); } public void consume(Integer value) { ... } } ====== Headline ======