Even in the
rules of plain old java, such an optimization would be valid if based on an
_expression_ only depending on private static final variables.
But Java
is not that language...
"It would be too
complex for the masses" - IOW - "We know better what you need to be more
efficient"
"Macro level
(compile time execution) is only needed for buggy languages like
c++"
"Dynamic reflection
means slow code"
"Strict typing is
The Holy Grail"
etc.etc.etc...
:)
Unfortuantely I
have to say that we should learn to live with it, or move on. Java is not that
language...
But IMHO your
example could work, and would be helpful nevertheless.
Just my 2
cents,
- 101
Hi all,
One of the features missing from
the java language is a pre-processor to handle conditional compilation.
Many people will point out that this was only really needed in C++ to handle
different platforms and that its possible to imitate #ifdef kind of constructs using static variables, which is
how the guys at Philips reduce their preprocessing directives for their Koala
component technology.
ie.
private final static boolean DEBUG = true;
..
if(DEBUG)
{ ... some
functionality
} whereby setting DEBUG as a static
variable would cause the compiler to include the code or not.
I've been wondering if it is possible to do the
same thing in AspectJ on advice, whereby the compiler would know that the
branches could not be reached so would not include them.
I put together a simple aspect as shown
below
aspect X
{ private final static
boolean CHECK = false; pointcut
something() : call (public void
SomeClass.printMsg(String)); pointcut check() :
if(CHECK); before() :something()
&& check()
{ //.. some
functionality
} }
but found after checking the bytecode that the
compiler converted the advice into a method even though it would never get
executed.
Is there a reason for this?
Cheers
Neil
|