Questions tagged [javac]

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

javac is the primary Java compiler, included in the Java Development Kit (JDK) from Sun Microsystems (now Oracle), and also in versions from other vendors.

The compiler accepts source code conforming to the Java language specification (JLS) and produces bytecode conforming to the Java Virtual Machine Specification (JVMS). javac is itself written in Java. The compiler can also be invoked programmatically.

2467 questions
20
votes
1 answer

How to avoid javac warning: unknown enum constant, reason: class file not found, when dependency has optional annotations with enums

I have this example setup: p.E package p; public enum E { E } p.A package p; import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) public @interface A { p.E e(); } q.Test package q; import p.*; @A(e = E.E) public class Test…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
20
votes
2 answers

Java casting: is the compiler wrong, or is the language spec wrong, or am I wrong?

I have been reading the Java Language Spec, 3rd edition, and have found what I think is a discrepancy between the spec and the javac compiler implementation. The same discrepancies exist in the Eclipse compiler. Section 15.16 talks about cast…
davmac
  • 20,150
  • 1
  • 40
  • 68
20
votes
7 answers

Exporting a package from system module is not allowed with --release

I have the following program: module-info.java module a { } Main.java public class Main { public static void main(String[] args) { System.out.println(sun.nio.ByteBuffered.class); } } This program successfully compiles with the…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
20
votes
6 answers

Compiling with JDK 1.8 java: cannot access class file... class file not found

Though the same code was getting to compiled successfully with JDK 1.6 version, after upgrading to JDK 1.8 it won't compile, saying java cannot access ....class file ...as class file not found though it exists. I am compiling this in IntelliJ Idea…
Anil Kamaraju
  • 481
  • 1
  • 4
  • 12
19
votes
1 answer

Why does compiling a class containing static nested classes create a new .class file named "EnclosingClass$1"?

In the below code : class EnclosingClass { public static class BiNode extends Sub.IBiLink { } private static class Sub { private static class IBiLink { } } } On compiling along with other .class…
paidedly
  • 1,413
  • 1
  • 13
  • 22
19
votes
1 answer

Config Maven 2 to print out javac commands during compile phase

Is there any way to force Maven 2 (>2.0.10) to print the actual javac commands it's executing. We keep running out of memory even though we've bumped up the max using MAVEN_OPTS. I'd like to be able to see the actual command being executed that is…
Chris Williams
  • 11,647
  • 15
  • 60
  • 97
18
votes
4 answers

Extract eclipse project .classpath dependencies into ant script

I have a list of Eclipse projects that I would like to compile based on the existing project configuration. As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and…
Nick
  • 5,765
  • 5
  • 27
  • 36
18
votes
3 answers

java 10 compilaton Null Pointer Exception

I recently installed jdk10. I was doing normal code and it is not working. Am I doing something wrong here? Please see the code and Exception stacktrace. As far as I understand there should be no reason for such behaviour. import…
Akshay Darekar
  • 191
  • 1
  • 5
18
votes
1 answer

"java.lang.NoSuchFieldError: super" exception - bug in compiler?

The following code written in Java-9 being run gives me a very weird and funny exception in runtime: Exception in thread "main" java.lang.NoSuchFieldError: super at A$C.test(A.java:15) at A.main(A.java:5) The code: public class A { …
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
17
votes
4 answers

Eclipse/javac disagree on compiling signature with default method collision; who is right?

Here's a simple class that demonstrates the issue: package com.mimvista.debug; public class DefaultCollisionTest { public static interface Interface1 { public String getName(); } public static interface Interface2 { …
BonusLord
  • 363
  • 1
  • 7
17
votes
2 answers

Lower-bounded wild card causes trouble in javac, but not Eclipse

This piece of code compiles in Eclipse but not in javac: import java.util.function.Consumer; public class Test { public static final void m1(Consumer c) { m2(c); } private static final void m2(Consumer c) { …
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
17
votes
6 answers

How can I exclude sources in a javac task in ant?

I have the following in my build.xml:
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
17
votes
3 answers

How to enforce a java compiler version with gradle?

In all of my projects, I use gradle and specify the following: sourceCompatibility = "1.7"; // for example targetCompatibility = "1.7"; // defaults to sourceCompatibility Now, I have three different versions of the JDK installed, from 1.6 to 1.8.…
fge
  • 119,121
  • 33
  • 254
  • 329
17
votes
1 answer

try with resources introduce unreachable bytecode

Is it possible that javac generates unreachable bytecode for the following procedure? public void ex06(String name) throws Exception { File config = new File(name); try (FileOutputStream fos = new FileOutputStream(config); …
Martin Schäf
  • 365
  • 1
  • 12
17
votes
3 answers

What is annotation processing in Java?

Quoting, Sun's Official Java Tutorial Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested What does it mean? And how to apply it?
Xolve
  • 22,298
  • 21
  • 77
  • 125