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
13
votes
6 answers

Cannot stop ant from generating compiler Sun proprietary API warnings

I call javac from my ant script like this: But it still throws compiler warnings in the output: [javac] Compiling 73…
Daniel
  • 27,718
  • 20
  • 89
  • 133
13
votes
2 answers

Illegal forward reference error for static final fields

I'm trying to compile a Java class which javac rejects with an illegal forward reference error, where the offending reference is lexically after the referenced field. The following class is stripped down as much as possible while showing the same…
Feuermurmel
  • 9,490
  • 10
  • 60
  • 90
13
votes
4 answers

Can javac compile from stdin?

Can javac compile from stdin? Something like this : cat myfile | javac
kofucii
  • 7,393
  • 12
  • 51
  • 79
13
votes
2 answers

Set ant bootclasspath: JDK 1.7 has a new javac warning for setting an older source without bootclasspath

How do I set the ant bootclasspath in conjunction with -source 1.5 -target 1.5? How can this not be a hardcoded path to the 1.5 JDK? Can I set an environment variable to bootclasspath similar to how JAVA_HOME can be used from ant? Ideally I would…
initialZero
  • 6,197
  • 9
  • 29
  • 38
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

How are anonymous classes compiled in Java?

I've heard that Java bytecode actually doesn't support any kind of unnamed classes. How does javac translate unnamned classes to named ones?
keiter
  • 3,534
  • 28
  • 38
13
votes
3 answers

How to suppress the "requires transitive directive for an automatic module" warning properly?

After upgrading a Maven project to Java 9 and adding a module descriptor, javac complains about a transitive dependency for an automatic module: [WARNING] /.../src/main/java/module-info.java:[3,35] requires transitive directive for an automatic…
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
13
votes
4 answers

Error: Failed to run "javac -version", make sure that you have a JDK Installed

Error: Failed to run "javac -version", make sure that you have a JDK installed. You can get it from: http://www.oracle.com/technetwork/java/javase/downloads. Your JAVA_HOME is invalid: C:\Program Files\Java\jdk1.8.0_152; [ERROR] An error…
Felipe Lima
  • 153
  • 1
  • 2
  • 9
13
votes
1 answer

Does the JLS require inlining of final String constants?

I ran into an issue while manipulating some bytecode, where a certain final String constant was not inlined by the java compiler (Java 8), see the example below: public class MyTest { private static final String ENABLED = "Y"; private static…
T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
13
votes
2 answers

Where is javac after installing new openjdk?

An additional jdk was installed and configured on RHEL5. yum install java-1.7.0-openjdk.x86_64 update-alternatives It appeared to work: java -version points to desired 1.7. However, javac -version still points to old 1.6. sudo update-alternatives…
Jacob
  • 349
  • 1
  • 2
  • 12
13
votes
3 answers

Target different version of JRE

I'm testing Java on a Windows Surface Pro. The Surface Pro has Java 7 Update 55, but does not have the JDK installed. I compiled a program on my MacBook from the command line using javac. The MacBook Has Java 8 Update 5 and it includes the JDK…
jww
  • 97,681
  • 90
  • 411
  • 885
13
votes
8 answers

Disabling compile-time dependency checking when compiling Java classes

Consider the following two Java classes: a.) class Test { void foo(Object foobar) { } } b.) class Test { void foo(pkg.not.in.classpath.FooBar foobar) { } } Furthermore, assume that pkg.not.in.classpath.FooBar is not found in the classpath. The…
knorv
  • 49,059
  • 74
  • 210
  • 294
13
votes
4 answers

javac "cannot find symbol" error with command line

I have two classes Owning and OwningAccessor. The files are in the same directory. public class Owning { String _name = ""; public void printBanner() { } public void printOwning(double amount) { printBanner(); …
prosseek
  • 182,215
  • 215
  • 566
  • 871
12
votes
3 answers

Does javac removes methods that are not referenced in the code?

I have a code base and some methods are never used. Does javac remove the unused methods from the class file?
CommonMan
  • 3,868
  • 2
  • 24
  • 35
12
votes
3 answers

Size of Initialisation string in java

Apparently there is a limit to the size of an initialisation string in javac. Can anyone help me in identifying what the maximum limit is please? Thank you edit: We are building an initialisation string which will look something like this…
Biscuit128
  • 5,218
  • 22
  • 89
  • 149