Possible regression bug in the compiler.

Andrej Golovnin andrej.golovnin at gmail.com
Tue Jan 12 21:11:17 UTC 2016

Hi all,

consider following example:

interface Value {

class ValueHolder implements Value {

class Model<T> {

  Model(T v) {
      System.out.println("Called constructor with generics");

  Model(Value v) {
      System.out.println("Called constructor with interface");

  public static void main(String... argv) {
      ValueHolder holder = new ValueHolder();
      Model<ValueHolder> m0 = new Model<>(holder);
      Model<ValueHolder> m1 = new Model<ValueHolder>(holder);


When I compile and execute it with Java 7, then it outputs:

Called constructor with generics
Called constructor with generics

When I compile and execute it with Java 8 and Java 9, then I get this output:

Called constructor with interface
Called constructor with generics

In Java 7 the compiler chooses in both cases, with the diamond
operand and with the provided type parameter, the constructor with generics.
In Java 8 and 9 only when I provide the type parameter.

Is it a bug or desired change?
From my standpoint of view there should be no difference,
if I use the diamond operand or not.

Best regards,
Andrej Golovnin

More information about the compiler-dev mailing list