javac

Setting the target version of Java in ant javac

冷暖自知 提交于 2019-11-27 12:32:40
I need to compile a jar file using ant (1.7.0) to run under a specific version of Java (1.5). I currently have Java 1.6 on my machine. I have tried setting: <target name="compile"> <javac compiler="javac1.5" target="1.5" srcdir=.../> </target> I have also removed <property name="build.compiler" value="modern"/> and there is no properties file. I am running Java 1.6 on Linux/SUSE Also is there a simple way of determining which version of Java is expected in the jar file. NawaMan Use "target" attribute and remove the 'compiler' attribute. See here . So it should go something like this: <target

In Java Lambda's why is getClass() called on a captured variable

為{幸葍}努か 提交于 2019-11-27 12:03:15
If you look at the byte code for Consumer<String> println = System.out::println; the byte code generates by Java 8 update 121 is GETSTATIC java/lang/System.out : Ljava/io/PrintStream; DUP INVOKEVIRTUAL java/lang/Object.getClass ()Ljava/lang/Class; POP INVOKEDYNAMIC accept(Ljava/io/PrintStream;)Ljava/util/function/Consumer; [ // handle kind 0x6 : INVOKESTATIC java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang

Differences between classpath and sourcepath options of javac

孤街醉人 提交于 2019-11-27 12:03:11
I read the Sun documentation and a lot of posts on Stack Overflow, but I'm still confused about the differences between the Java compiler options -cp and -sourcepath . Let say I have this directory structure: c:\Java\project1\src (where the Java source files are) c:\Java\project1\bin (where the Java class files will be or already are) Let's also say I have a source file MainClass.java in a package com.mypackage , and that the directory structure is ok in the source folder. I'm in the project1 directory and run: javac -d bin -sourcepath src src/com/mypackage/MainClass.java or javac -d bin

Is there a performance difference between Javac debug on and off?

跟風遠走 提交于 2019-11-27 11:45:28
If I switch on the generating of debug info with Javac then the class files are 20-25% larger. Has this any performance effects on running the Java program? If yes on which conditions and how many. I expect a little impact on loading the classes because the files are larger but this should be minimal. In any language, debugging information is meta information. It by its nature increases the size of the object files, thus increasing load time. During execution outside a debugger, this information is actually completely ignored. As outlined (although not clearly) in the JVM spec the debug

Is this valid Java?

拜拜、爱过 提交于 2019-11-27 11:11:23
Is this valid Java? import java.util.Arrays; import java.util.List; class TestWillThatCompile { public static String f(List<String> list) { System.out.println("strings"); return null; } public static Integer f(List<Integer> list) { System.out.println("numbers"); return null; } public static void main(String[] args) { f(Arrays.asList("asdf")); f(Arrays.asList(123)); } } Eclipse 3.5 says yes Eclipse 3.6 says no Intellij 9 says yes Sun javac 1.6.0_20 says yes GCJ 4.4.3 says yes GWT compiler says yes Crowd at my previous Stackoverflow question says no My java theory understanding says no ! It

unable to run javac on Ubuntu [closed]

浪子不回头ぞ 提交于 2019-11-27 11:09:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I'm trying to run javac on a Ubuntu terminal. But I get the following: $ javac The program 'javac' can be found in the following packages: * openjdk-6-jdk * ecj * gcj-4.4-jdk * gcj-4.6-jdk * gcj-4.5-jdk * openjdk-7-jdk Try: sudo apt-get install <selected package> jdk is already installed and running sudo apt-get

javac.exe AST programmatic access example

∥☆過路亽.° 提交于 2019-11-27 10:03:05
问题 Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example? 回答1: Yes, it is possible, but only since Java 6. Peter von der Ahé talks about the two JSRs in this interview. Of JSR 199: The JSR 199 Compiler API consists of three things: The first one basically allows you to invoke a compiler via the API. Second, the API allows you to customize how the compiler finds and writes out files. I mean files in the abstract sense, since the

Multiple .class files generated for a class?

不想你离开。 提交于 2019-11-27 09:14:09
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 MyClass#10. These are for inner classes and static nested classes . The ones with numbers are anonymous inner classes. For example: class Foo { class Bar { } static class Baz { } void run() { Helper t = new Helper() { int helpMethod() { return 2; } }; } } This will produce class files Foo.class , Foo$Bar.class , Foo$Baz.class and Foo$1.class (for the

How to set a java compiler in Netbeans

孤街浪徒 提交于 2019-11-27 09:12:45
I'm getting into Java7 development and I've added JDK7 into Java Platforms and have selected it in the project properties. But when I'm compiling, I get messages like: warning: java/lang/Boolean.class(java/lang:Boolean.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. and javac: invalid target release: 1.7 /Applications/NetBeans/NetBeans 7.1.app/Contents/Resources/NetBeans/harness/suite.xml:184: The following error occurred while executing this line: /Applications/NetBeans/NetBeans 7.1.app/Contents

javac optimization flags [duplicate]

故事扮演 提交于 2019-11-27 09:11:20
This question already has an answer here: Optimization by Java Compiler 5 answers I've recently been writing a lot of code in C and am now switching over to Java. I'm currently implementing a large data structure and was wondering whether there were any optimization flags I can turn on when I invoke the Java compiler in order to improve performance like in gcc. I'm used to: gcc -O3 -NDEBUG MyProgram.c is there an analogous command for javac ? I'm using JDK and am running Ubuntu 10.04. Optimization in Java is mostly done by the JIT compiler at runtime. Hence there is no point trying to instruct