javac

Discover the class of a methodinvocation in the Annotation Processor for java

戏子无情 提交于 2019-11-28 22:01:45
I am writing some tools for our build system to enforce some strict calling conventions on methods belonging to classes containing certain annotations. I'm using the Compiler Tree API... What i'm wondering is when traversing the 'tree', how can you tell the type of class/interface for a MethodInvocation. I'm subclassing TreePathScanner with : @Override public Object visitMethodInvocation(MethodInvocationTree node, Trees trees) { } I'm hoping theres a way to tell the type of the class(or interface) that you're trying to invoke the method on. Am I going about this the wrong way? Thanks for any

Why do lambdas in Java 8 disallow forward reference to member variables where anonymous classes don't?

落花浮王杯 提交于 2019-11-28 21:18:11
The following class contains a member variable runnable which is initialized with an instance of an anonymous inner class. The inner class references the same member: class Example { Runnable runnable = new Runnable() { @Override public void run() { System.out.println(runnable); } }; } This is not a problem as long as the method is not executed before the member has been assigned and the JLS allows such a reference. The declaration of the member variable could theoretically be converted to a lambda expression like this: Runnable runnable = () -> System.out.println(runnable); To my

How to run a .class file that is part of a package from cmd?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 19:08:28
I keep getting errors when I make my .class part of a package and try to run it from cmd. Here's the code that works after using javac and then java: class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } and then the code that does not work: package com; class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } giving me this error after trying to run the program via the command: java HelloWorld : Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong nam e: com/HelloWorld) at java

unable to run javac on Ubuntu [closed]

懵懂的女人 提交于 2019-11-28 18:15:45
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 install openjdk-6-jdk says 0 upgraded, 0 newly installed, 0 to remove and 322 not upgraded. My jdk is installed in /usr/lib/jvm/java-6-open-jdk; and I'm able to compile and run a java program from eclipse. But I'm having this fore-mentioned problem when using a terminal. The javac

javac.exe AST programmatic access example

…衆ロ難τιáo~ 提交于 2019-11-28 16:55:15
Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example? jamesh 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 files the compiler deals with aren't necessarily on the file system. JSR 199's file abstraction

Difference in behaviour of the ternary operator on JDK8 and JDK10

我们两清 提交于 2019-11-28 16:36:42
问题 Consider the following code public class JDK10Test { public static void main(String[] args) { Double d = false ? 1.0 : new HashMap<String, Double>().get("1"); System.out.println(d); } } When running on JDK8, this code prints null whereas on JDK10 this code results in NullPointerException Exception in thread "main" java.lang.NullPointerException at JDK10Test.main(JDK10Test.java:5) The bytecode produced by the compilers is almost identical apart from two additional instructions produced by the

Compiling four java files within one package using javac

岁酱吖の 提交于 2019-11-28 16:13:56
I have four java files in my folder. They are all in the same package. Here's the package declaration package com.osama.GHide All of these classes are in the same package. I want to know how can I compile them using javac (i mean i do not know how to compile multiple files that are using each other). And once that is done how do I launch then using java command in the CLI? here are the file names. EnteringPoint.java HidingProcess.java ListFiles.java From the project's root directory: javac src/com/osama/GHide/*.java To run, assuming no other dependencies: java -cp ./src com.osama.GHide

Android: javac vs Dalvik

守給你的承諾、 提交于 2019-11-28 15:23:36
问题 My understanding is that Google didn't like Oracle's licensing policy for using the JRE in Java ME so it just rewrote it using its own JVM specification that mimics the JRE but behaves a little bit differently, especially when it comes to making things more efficient and more secure. So, if my understanding is correct, it means that when javac is ran on some Java source code and compiled into "binary" byetcode, a compliant JVM will interpret that bytecode different than Dalvik will (in some

javac classpath option with multiple jar files in current directory causing error

别等时光非礼了梦想. 提交于 2019-11-28 13:43:06
Environment: Windows 7, Java 6. Trying to compile a .java file with -cp option. The file uses a single jar file that's in the current directory ALONG WITH some other jar files in the current directory. javac -cp ./*.jar MyFile.java doesn't work. javac -cp ./* MyFile.java doesn't work javac -cp ./MyJar.jar MyFile.java works First two cases, I get a invalid flag error. Can someone explain this behavior? And I checked if it is spaces issue, there are no spaces anywhere in my full file paths. The quoted sources for the two links provided in the comments as well as in the "This question may already

Target different version of JRE

懵懂的女人 提交于 2019-11-28 13:23:14
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 (obviously because I compiled on the MBP). When I move the program from the MackBook to the Surface Pro, I get the following error. Here, "moving the program" means copying the two *.class files to the new machine and trying to execute the byte codes. java.lang.UnsupportedClassVersionError: HttpsTest : Unsupported major.minor version 52. Trying to