javac

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

不问归期 提交于 2019-11-29 13:09:41
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 an inner/embedded class in the byte code. I am wondering if there is any risk to use a dollar sign $ as a class name Some background to this question. What I want to do is to overcome the fact that Java doesn't support pure function, and the _ or $ is to put an namespace to encapsulate some very generic concept (classes/static methods). and

Java: How will JVM optimise the call to a void and empty function?

一世执手 提交于 2019-11-29 12:21:11
问题 Let's imagine we have the following classes: public class Message extends Object {} public class Logger implements ILogger { public void log(Message m) {/*empty*/} } and the following program: public static void main(String args[]) { ILogger l = new Logger(); l.log((Message)null); // a) l.log(new Message()); // b) } Will the Java compiler strip out statements a and b ? In both cases (stripping or not stripping), what is the rationale behind the Java compiler's decision ? 回答1: Will the Java

Javac Cross-Compilation with 1.7

与世无争的帅哥 提交于 2019-11-29 11:26:31
问题 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 windows and the cmd): javac -target 1.6 -source 1.7 -bootclasspath /usr/java/jdk1.6.0_27/jre/lib/rt.jar Main.java with Main.java with nothing other than a System.out.println. javac -version ==> javac 1.7.0_11 I'm getting the error message: javac:

Package not found; javac

梦想的初衷 提交于 2019-11-29 11:17:55
This is annoying. I have a directory structure like this -lib --some jar files -packageName --Main.java --SomeOtherPackage --SomeOtherJavaClass.java Main.java imports SomeOtherPackage . And both java files uses jars in the lib. What I do is add the jar files independently in the CLASSPATH. And then run as: javac packageName/Main.java but it gives the error that Package not found SomeOtherPackage . Shouldn't it automatically realize the dependency and build SomeOtherPackage as well? What would be the javac command and the classpath for the above case? Thanks The normal practice is to add the

Why does the compiler state no unique maximal instance exists?

拥有回忆 提交于 2019-11-29 10:54:26
问题 I have the following classes: public class Obj<T> extends BaseModel { public static final String OBJECT = "object"; public Obj(T object) { setObject(object); } public T getObject() { return get(OBJECT); } public void setObject(T object) { set(OBJECT, object); } } And... /** This is a 3rd party library class **/ public class BaseModel implements ModelData, Serializable { //...members and stuff... @SuppressWarnings({"unchecked", "rawtypes"}) public <X> X get(String property) { X obj = null; if

javac code elimination capabilities

佐手、 提交于 2019-11-29 10:32:47
I'm having a hard time finding information about javac 's code elimination capabilities: I read that if you have something like the following, the if -statement will be eliminated: static final boolean DEBUG = false; if (DEBUG) System.out.println("Hello World!"); // will be removed But how about this, for example: static final int VALUE = 3; if (VALUE > 9) System.out.println("VALUE > 9 ???"); // will this be removed? Or this: static final SomeEnum VALUE = SomeEnum.FOO; if (VALUE==SomeEnum.BAR) System.out.println("Bar???"); // will this be removed? Since it's very difficult/impossible to

“Cannot find symbol” for my own class

旧时模样 提交于 2019-11-29 10:01:58
I do not have a %CLASSPATH% set up. As I understand, this should not be a problem because Javac will assume a classpath of the current directory. As you can see below, javac is unable to find my Case class even though it's in the same exact directory. Any thoughts on why this is happening? This code works fine when I use Eclipse. C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>dir /B Case.class Case.java EntryPoint.java C:\Documents and Settings\joep\My Documents\GCJ\src\codejam2011\Round0\D>javac EntryPoint.java EntryPoint.java:16: cannot find symbol symbol : class

Config Maven 2 to print out javac commands during compile phase

情到浓时终转凉″ 提交于 2019-11-29 09:23:04
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 running out of memory. I've tried using the verbose setting below in the pom file's plugin management section but that doesn't seem to give me the javac command: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> <maxmem>1024m</maxmem>

Deprecated compiling error

安稳与你 提交于 2019-11-29 08:36:42
问题 I'm trying to compile my Java program, however I am getting a "Deprecated File" error. I normally compile the file by typing "Javac FileName.java", however I get an error saying: FileName.java uses or overrides a depreacted API. Recompile with Xlint-deprecation for details. What do I type into the command line to make it run? 回答1: It's not an error, just a warning . The compiler will still produce a class file and you will be able to run it. However, it's a good idea to address the warning,

Creating a PHP Online Grading System on Linux: exec Behavior, Process IDs, and grep

て烟熏妆下的殇ゞ 提交于 2019-11-29 08:05:46
Background I am writing a simple online judge (a code grading system) using PHP and MySQL. It takes submitted codes in C++ and Java, compiles them, and tests them. This is Apache running PHP 5.2 on an old version of Ubuntu. What I am currently doing I have a php program that loops infinitely, calling another php program by //for(infinity) exec("php -f grade.php"); //... every tenth of a second. Let's call the first one looper.php and the second one grade.php . (Checkpoint: grade.php should completely finish running before the "for" loop continues, correct?) grade.php pulls the earliest