code-elimination

javac code elimination capabilities

混江龙づ霸主 提交于 2020-01-20 05:59:44
问题 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

Java constant expressions and code elimination

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 02:08:01
问题 As discussed here, javac and other Java compilers may provide code elimination capabilities for if -statements where the condition is a "Constant Expression". How is this affected if my code uses a constant expression that depends on other constant expressions defined in different packages? For example, let's say I have the following classes in the respective specified packages: package foo; public class Foo { public static final boolean CONDITION = false; } and package bar; import foo.Foo;

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