Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diamond operator type inference fails under javac but not ECJ #3588

Open
datho7561 opened this issue Jan 21, 2025 · 1 comment
Open

Diamond operator type inference fails under javac but not ECJ #3588

datho7561 opened this issue Jan 21, 2025 · 1 comment
Labels
javac ecj not compatible with javac rawtypes Test triggers raw types warning

Comments

@datho7561
Copy link
Contributor

The following minimal example produces a compiler error under javac but not ECJ:

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class HelloWorld {
	public static void main(String... args) {
		Class[] classes = new Class[] { String.class, List.class };
		List<Class<?>> asdf = new ArrayList<>(Arrays.asList(classes));
	}
}

Here's the error that javac gives:

HelloWorld.java:9: error: incompatible types: cannot infer type arguments for ArrayList<>
                List<Class<?>> asdf = new ArrayList<>(Arrays.asList(classes));
                                                   ^
    reason: cannot infer type-variable(s) E,T
      (argument mismatch; List<Class> cannot be converted to Collection<? extends Class<?>>)
  where E,T are type-variables:
    E extends Object declared in class ArrayList
    T extends Object declared in method <T>asList(T...)
@datho7561 datho7561 changed the title Diamond operator type inferences fails under javac but not ECJ Diamond operator type inference fails under javac but not ECJ Jan 21, 2025
@jukzi jukzi added the javac ecj not compatible with javac label Jan 22, 2025
@stephan-herrmann stephan-herrmann added the rawtypes Test triggers raw types warning label Jan 27, 2025
@stephan-herrmann
Copy link
Contributor

$ ecj  -23 -warn:+all HelloWorld.java 
----------
1. WARNING in /tmp/HelloWorld.java (at line 7)
        Class[] classes = new Class[] { String.class, List.class };
        ^^^^^
Class is a raw type. References to generic type Class<T> should be parameterized
----------

Let's not spend time on compiler difference where raw types are involved. Those are legacy since about 20 years. Knowing that javac has some significant, long standing bugs in this area, we can simply blame them :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javac ecj not compatible with javac rawtypes Test triggers raw types warning
Projects
None yet
Development

No branches or pull requests

3 participants