ecj

Method signature selection for lambda expression with multiple matching target types

别说谁变了你拦得住时间么 提交于 2020-06-10 07:51:45
问题 I was answering a question and ran into a scenario I can't explain. Consider this code: interface ConsumerOne<T> { void accept(T a); } interface CustomIterable<T> extends Iterable<T> { void forEach(ConsumerOne<? super T> c); //overload } class A { private static CustomIterable<A> iterable; private static List<A> aList; public static void main(String[] args) { iterable.forEach(a -> aList.add(a)); //ambiguous iterable.forEach(aList::add); //ambiguous iterable.forEach((A a) -> aList.add(a)); /

Method signature selection for lambda expression with multiple matching target types

泄露秘密 提交于 2020-06-10 07:51:11
问题 I was answering a question and ran into a scenario I can't explain. Consider this code: interface ConsumerOne<T> { void accept(T a); } interface CustomIterable<T> extends Iterable<T> { void forEach(ConsumerOne<? super T> c); //overload } class A { private static CustomIterable<A> iterable; private static List<A> aList; public static void main(String[] args) { iterable.forEach(a -> aList.add(a)); //ambiguous iterable.forEach(aList::add); //ambiguous iterable.forEach((A a) -> aList.add(a)); /

What does var<T> do in Java?

不羁岁月 提交于 2020-06-08 16:56:51
问题 A friend of mine noticed that var<Integer> list = new ArrayList<Double>(); was valid in Java. It turns out that the type of list is evaluated to ArrayList<Double> . When using var<Integer> list = new ArrayList<>(); , list is just ArrayList<Object> . Both of us were not able to figure out, what the generic type of var does, as it seems to be ignored. But if so, why is this even syntactically correct in the first place? 回答1: This is indeed a bug, but the proof lies in the Java Language

Is eclipse's ecj compiler extensible?

筅森魡賤 提交于 2020-02-25 06:32:16
问题 I am interested in modifying java syntax and some implicit paradigms. Since I develop with eclipse which provides it's own compiler, which can also be used standalone, I was wondering if it wasn't possible to extend ecj to respect additional grammar rules (and correctly handle them). My syntactical changes are all resolvable by removing elements from the AST and creating some new ones, so I assume that what I want to do is possible without diving into bytecode. Essentially, what I want to do

Strange java.lang.ClassNotFoundException when compiling drools rules (v5.0.1) on Java 8 on Rule Name as class

柔情痞子 提交于 2019-12-25 01:22:23
问题 Trying to get drools to run java8 jvm (upgraded from Java6). However, compilation has failed and the goal pushed further. Did a couple of things that helped: Ecj compiler: updated to 'org.eclipse.jdt.core.compiler:ecj:4.5.1' Mvel: Using updated mvel2-2.1.3.Final.jar Additionally, added org.codehaus.janino:janino:jar:2.5.16 to compile dependency to use janino compiler as per this https://copyrightdev.tumblr.com/post/146315831773/getting-drools-5x-to-operate-smoothly-with-java-8 blog. However,

Method references to raw types harmful?

巧了我就是萌 提交于 2019-12-19 06:04:58
问题 The code below contains a reference to Enum::name (notice no type parameter). public static <T extends Enum<T>> ColumnType<T, String> enumColumn(Class<T> klazz) { return simpleColumn((row, label) -> valueOf(klazz, row.getString(label)), Enum::name); } public static <T, R> ColumnType<T, R> simpleColumn(BiFunction<JsonObject, String, T> readFromJson, Function<T, R> writeToDb) { // ... } Javac reports a warning during compilation: [WARNING] found raw type: java.lang.Enum missing type arguments

Method references to raw types harmful?

一世执手 提交于 2019-12-19 06:04:22
问题 The code below contains a reference to Enum::name (notice no type parameter). public static <T extends Enum<T>> ColumnType<T, String> enumColumn(Class<T> klazz) { return simpleColumn((row, label) -> valueOf(klazz, row.getString(label)), Enum::name); } public static <T, R> ColumnType<T, R> simpleColumn(BiFunction<JsonObject, String, T> readFromJson, Function<T, R> writeToDb) { // ... } Javac reports a warning during compilation: [WARNING] found raw type: java.lang.Enum missing type arguments

Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gradle 4.1 task

ぐ巨炮叔叔 提交于 2019-12-13 17:50:23
问题 I have a project that can be build well by eclipse (ECJ) But Oracle javac can't build it (some reasons like in link: the different of ecj and javac). I would like moving from eclipse to build by Gradle, in order to Jenkins can run Gradle script. But Gradle always use javac to compile. I used the plugins 'eclipse, eclipse-wtp' or library, dependency of jdt to config gradle use ECJ like that but it still don't use ECJ to compile: compileJava{ options.forkOptions.with { executable = 'java'

How to compile this code with Java 10, Ant and the Eclipse compiler?

自作多情 提交于 2019-12-10 15:28:36
问题 I am trying to compile this simple code using Java 10, Ant and the Eclipse compiler: import java.util.ArrayList; import javax.xml.bind.JAXBException; class Test { void foo() throws JAXBException { throw new JAXBException("hi there"); } void bar() { new ArrayList<String>(); } } This is the Ant file I am using: <project name="Java 10 test"> <target name="compile-javac" depends="clean, print-version-info"> <javac release="10" includeantruntime="false"> <src path="."/> <compilerarg value="--add

Mockito: Verifying overloaded methods with type-compatible arguments

偶尔善良 提交于 2019-12-06 04:23:44
问题 Consider you want to mock an interface using Mockito containing the following method signatures: public void doThis(Object o); public void doThis(Object... o) I need to verify that doThis(Object o) (and not the other method) has been invoked exactly one time. First I thought that the following line would do the trick: verify(mock, times(1)).doThis(anyObject()); However, as this seems to work on Windows, it doesn't on Linux because in this environment, a call to of the other doThis method is