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
17
votes
2 answers

Javac Cross-Compilation with 1.7

So guys, I'm trying to play a bit with Javac Cross compilation with Ant and on terminal. Locally and on an integration environment and i'm having the same problem on the very basic problem. I run this in the linux terminal (and also on my cygwin on…
Eyad Ebrahim
  • 971
  • 1
  • 8
  • 21
17
votes
1 answer

Compile in Java 6, run in 7 - how to specify useLegacyMergeSort?

I'm wondering if I compile in Java 6, but someone runs the program on Java 7, will the Java 6 or 7 version of Arrays.sort be used? It's important because the new mergesort throws an IllegalArgumentException, and the old one doesn't (see Comparison…
Alex
  • 18,332
  • 10
  • 49
  • 53
17
votes
9 answers

Multiple .class files generated for a class?

Out of curiosity, why are sometimes multiple Java .class files generated for a class after compilation? For example, my application has six classes. For one class, a total of 10 .class files has been generated, starting from MyClass#1 up to…
Ariod
  • 5,757
  • 22
  • 73
  • 103
16
votes
2 answers

How to suppress "warning: Ignoring InnerClasses attribute for an anonymous inner class" with Gradle?

How to suppress "warning: Ignoring InnerClasses attribute for an anonymous inner class" with Gradle? This not a duplicate question This not during Proguard nor do I want to suppress using Proguard I would like to suppress doing normal ./gradlew…
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
16
votes
5 answers

java compiler says this exception is never thrown in body of corresponding try statement - but it _is_ thrown

I have the following code: try { //jaw-ws service port operation port.login(); } catch (Exception e) { logger.error("Caught Exception in login(): " + e.getMessage()); } When the above is run with an incorrect hostname, I get: Caught…
rouble
  • 16,364
  • 16
  • 107
  • 102
16
votes
3 answers

How does javac automatically compile dependencies of a class

Given the following directory structure: /top |--- wrk |--- pkg |--- A.java |--- B.java Assume that the two files A.java and B.java contain the following code, respectively: // Filename:…
paidedly
  • 1,413
  • 1
  • 13
  • 22
16
votes
4 answers

Why calling method with generic return on a generic class is considered unsafe by javac?

Consider the following code: public class Main { public static class NormalClass { public Class method() { return Integer.class; } } public static class GenericClass { public…
Juan Lopes
  • 10,143
  • 2
  • 25
  • 44
16
votes
2 answers

Does Javac's StringBuilder optimisation do more harm than good?

Let's say we have some code such as the following: public static void main(String[] args) { String s = ""; for(int i=0 ; i<10000 ; i++) { s += "really "; } s += "long string."; } (Yes, I know a far better implementation…
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
16
votes
5 answers

Any risk using a single dollar sign `$` as a java class name?

Originally I was using the underscore _ as a class name. The new Java8 compiler complains that it "might not be supported after Java SE 8". I changed that to $, and there is no warning any more. However I remember that $ is used by Java to indicate…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
16
votes
6 answers

How do I find out what jar files are actually used when compiling a java project

I'm currently passing a very large classpath to javac to compile a java project. I know that a number of those jar files aren't needed. Is there a simple way of finding out which files aren't needed?
tomdee
  • 2,319
  • 5
  • 25
  • 39
16
votes
1 answer

Why does this code compile in Java 1.6 but not in Java 1.7?

The following code compiles fine in Java 1.6 but fails to compile in Java 1.7. Why? The relevant part of the code is the reference to the private 'data' field. The reference is from within the same class in which the field is defined, and so seems…
Paul
  • 3,009
  • 16
  • 33
16
votes
3 answers

Setup Java 6 annotation processing configuration for eclipse compiler with maven

What's the best way to setup the eclipse project compiler configuration for Java 6 annotation processors? My solution is to setup the org.eclipse.jdt.apt.core.prefs and factorypath files manually. This is a bit cumbersome: Reference the processor…
Thomas Jung
  • 32,428
  • 9
  • 84
  • 114
16
votes
4 answers

Can a compliant Java compiler optimize this code?

I was teaching an introductory programming course today and was walking through some simple code involving variable assignments in Java. The point of the code wasn't to show off anything particular exciting, but mostly to make sure students…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
16
votes
3 answers

Why does the Java compiler sometimes allow the unboxing of null?

For example: int anInt = null; fails at compile time but public static void main(String[] args) { for (int i = 0; i < 10; i++) { System.out.println("" + getSomeVal()); } } public static int getSomeVal() { return new…
MilesHampson
  • 2,069
  • 24
  • 43
16
votes
1 answer

Java 1.7 varargs function reported as unchecked warning

We use some varargs functions and as we move to java 1.7 we are getting a strange unchecked warning. Function add in interface ICache public interface ICache { void add(Object source, O... objects); } in an interface reports the…
Neil Wightman
  • 1,103
  • 2
  • 9
  • 29