2

Long story short, following code is not compiling in Java 8 but was compiling and executing well in Java 7:

public static void main(final String[] args) {
    final Class instance = null;
    meth(instance); // compiler error here
}

private static <K, T extends Enum<T> & IAliased<K>> void meth(final Class<T> clazz) {

}

The error occurs at mentioned line with message: The method meth(Class<T>) in the type AnotherSpike is not applicable for the arguments (Class).

While I totally understand that such code is not 100% typesafe, I need very similar invocation working in production code in Java 8 (and it was compiling with warnings and working well in Java 7).

The interesting thing is that above code compiles fine (with warnings, but this is ok) in following cases:

  1. if & IAliased<K> is removed from method signature:

    private static <K, T extends Enum<T>> void meth(final Class<T> clazz)
    
  2. if & IAliased<K> is replaced with & IAliased in signature:

    private static <K, T extends Enum<T> & IAliased> void meth(final Class<T> clazz)
    

Two above observations has lead me to the thought that this is more like a compiler bug in Java 8 rather than thoughtful enhancement to the Java 8 compiler, though I may be mistaken.

Anyway, can somebody advise on how can I pass raw instance of Class to meth method with such signature without compiler errors?

Thanks in advance for any help!

Yuriy Nakonechnyy
  • 3,742
  • 4
  • 29
  • 41
  • 3
    Hmmm ... While compiling with `javac` I still get only the warnings, Eclipse gives me the error you describe. This is most likely a bug in the IDE's internal compiler. – Seelenvirtuose Dec 15 '14 at 16:55
  • @Seelenvirtuose you're absolutely right - just tried with `javac` and it compiled with warnings. My bad that I didn't tried it in `javac` first. I will create bug for JDT and post a link to it here. BTW, please put your comment as an answer if you want it to be upvoted and accepted :) – Yuriy Nakonechnyy Dec 15 '14 at 17:22

1 Answers1

4

This seems to be a bug in the IDE's internal compiler.

With Eclipse I get the same error you are describing. However, when using the JDK compiler I still get only the warnings and it compiles.

Seelenvirtuose
  • 20,273
  • 6
  • 37
  • 66