Questions tagged [ecj]

Eclipse has implemented its own compiler called as Eclipse Compiler for Java (ECJ). This tag is for questions relating to the behaviour of that compiler.

ECJ is different from javac, the compiler that is shipped with Sun JDK. One notable difference is that the Eclipse compiler lets you run code that didn't actually properly compile. If the block of code with the error is never ran, your program will run fine. Otherwise, it will throw an exception indicating that you tried to run code that doesn't compile.

Another difference is that the Eclipse compiler allows for incremental builds from within the Eclipse IDE, that is, all code is compiled as soon as you finish typing.

The fact that Eclipse comes with its own compiler is also apparent because you can write, compile, and run Java code in Eclipse without even installing the Java SDK.

Further reading: What is the difference between javac and the Eclipse compiler? (from which the above text was taken).

67 questions
38
votes
1 answer

Why does javac insert Objects.requireNonNull(this) for final fields?

Consider the following class: class Temp { private final int field = 5; int sum() { return 1 + this.field; } } Then I compile and decompile the class: > javac --version javac 11.0.5 > javac Temp.java > javap -v Temp.class …
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
17
votes
2 answers

Using Eclipse Java Compiler (ecj) in maven builds

Eclipse uses it's own compiler (ECJ) to compile Java code. Debugging a program compiled with Eclipse is easier, because simple code changes can be applied instantly (by the hot code replacement). Maven on the other hand uses (by default) oracle JDK,…
Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
15
votes
2 answers

Ambiguous overload in Java8 - is ECJ or javac right?

I have the following class: import java.util.HashSet; import java.util.List; public class OverloadTest extends HashSet> { private static final long serialVersionUID = 1L; public OverloadTest(OverloadTest other) {} …
Ian Robertson
  • 1,312
  • 1
  • 13
  • 14
13
votes
3 answers

Method signature selection for lambda expression with multiple matching target types

I was answering a question and ran into a scenario I can't explain. Consider this code: interface ConsumerOne { void accept(T a); } interface CustomIterable extends Iterable { void forEach(ConsumerOne c);…
ernest_k
  • 44,416
  • 5
  • 53
  • 99
13
votes
1 answer

Strange "!*" entry in LocalVariableTypeTable when compiling with Eclipse compiler

Let's compile the following code with ECJ compiler from Eclipse Mars.2 bundle: import java.util.stream.*; public class Test { String test(Stream s) { return s.collect(Collector.of(() -> "", (a, t) -> {}, (a1, a2) -> a1)); …
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
12
votes
2 answers

This code compiles using ecj but not javac. Is this a bug in ecj, javac or neither?

The following code creates a Collector that produces an UnmodifiableSortedSet: package com.stackoverflow; import java.util.Collections; import java.util.SortedSet; import java.util.TreeSet; import java.util.stream.Collector; import…
Robert Bain
  • 9,113
  • 8
  • 44
  • 63
10
votes
0 answers

`\u0027\n\u0027` equals `'\''` in Java?

I was playing around with Java Unicode Escapes and accidentally found the following interesting oddities. Here is the code that I wrote: static void main(String... args) { /* * \u0027 - single quote */ char e =…
Microtribute
  • 962
  • 10
  • 24
10
votes
1 answer

Why can't the eclipse java compiler (ecj) compile this?

I have the following code: package test; import java.util.stream.IntStream; public class A { public static void main(String[] args) { IntStream.range(0, 10).mapToObj(n -> new Object() { int i = n; }).mapToInt(o ->…
Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73
9
votes
2 answers

What does var do in Java?

A friend of mine noticed that var list = new ArrayList(); was valid in Java. It turns out that the type of list is evaluated to ArrayList. When using var list = new ArrayList<>();, list is just…
Joja
  • 370
  • 2
  • 11
9
votes
1 answer

Method references to raw types harmful?

The code below contains a reference to Enum::name (notice no type parameter). public static > ColumnType enumColumn(Class klazz) { return simpleColumn((row, label) -> valueOf(klazz, row.getString(label)),…
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
8
votes
2 answers

Should JDK 9 not allow Lambda Expression instantiation where final fields are referenced in the overridden method?

I've been working with the new Eclipse Neon and some of my code started to give me errors straight away. This was strange to me at first, but then I found here that the Neon ECJ(Eclipse Java Compiler) adopts the attitude of the JDK 9 early release…
aaiezza
  • 1,297
  • 3
  • 11
  • 21
7
votes
1 answer

How often is "incremental compilation" performed on Java in Eclipse/ Intellij?

I understand that Eclipse uses it's own compiler for Java (ECJ) which has the ability to perform incremental compilation. From most of the readings I have found, this compilation is generally triggered by a save action, but that doesn't seem to…
user3601148
  • 175
  • 1
  • 9
7
votes
1 answer

Enum disassembled with javap doesn't show constructor arguments

When I disassemble an enum with javap, the enum's implicit constructor arguments seem to be missing, and I can't figure out why. Here's an enum: enum Foo { X } I compile and disassemble this (on Java 8u60) with this command: javac Foo.java && javap…
Boann
  • 48,794
  • 16
  • 117
  • 146
6
votes
1 answer

Java import static fails when imported class extends 3rd party lib

The problem setup consists of three java libs (I stripped all package names for readability, full qualified names are used everywhere): external-lib: provides the abstract class public abstract class AbstractExternal {} my-lib-A: provides the…
6
votes
1 answer

Java 8 generics The method ... is not applicable for the arguments in Eclipse

During the migration of our code base from java 1.7 to 1.8 we’ve got an error message "The method ... is not applicable for the arguments" on several code locations, all following the same pattern in generics usage. We are currently using mostly…
Tomasz Stanczak
  • 12,796
  • 1
  • 30
  • 32
1
2 3 4 5