private static final fields not removed after compilation???

H

Henri

I'm using lots of private static final fields inside my source so that I can
manage constants easily.
Once the source is compiled, these fields become useless as the compiler
replace each constant name by its value.
But the fields themselves are not removed.
I thought that it would work like DEFINE is C, but it doesn't.
Even the obfuscator Proguard doesn't remove these useless fields that must
make the .jar bigger.
Did I miss something?
Can you help me?
Thanks !
 
H

Henri

But all my constants are private, so how another source using the classes
containing these private constants would have access to them?
Anyway, is there any shrinker/obfuscator that would remove them?
Thanks for your help!

Henri
 
R

Roedy Green

I'm using lots of private static final fields inside my source so that I can
manage constants easily.

They have a use during compilation. Other classes being compiled look
at the class file to help them compile too. A make program in theory
should be able to notice these and ensure all gets recompiled if a
constant value changes.

Class files are quite tiny compared with native exe files. Further
strings compact well inside jars. You are sweating the small stuff.
 
T

Tim Tyler

: But all my constants are private, so how another source using the classes
: containing these private constants would have access to them?
: Anyway, is there any shrinker/obfuscator that would remove them?

Probably.

JAX used to do that - even if they were public - I believe.

Also, try JoGa: http://www.nq4.de/
 
J

James Hicks

Are the constants primitive types? if they are, just write a utlity that
modifies the byte code - look at jakarta for an example byte code
manipulation utility.

If they are non-primitive types, the compiler shouldn't inline them.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top