Something that's declared final will be substituted with its literal value at compile time if (and only if) it is initialized with a literal value (or an expression that can be resolved to a literal at compile time).
For example: the literal value for a case must be determined at compile time, so you can do this:
Code:
public static final int FISH = 0;
public static final int DOG = 1;
switch (animal) {
case FISH: // will get replaced with 0
break;
case DOG: // will get replaced with 1
break;
}
And you can also do this:
Code:
public static final int FISH = 0;
public static final int DOG = FISH + 1;
switch (animal) {
case FISH:
break;
case DOG:
break;
}
But you can't do this:
Code:
// this is legal...
public static final int FISH = getNextEnumerationValue();
public static final int DOG = getNextEnumerationValue();
// ...but this isn't, because the "constants" are initialized from method calls
switch (animal) {
case FISH:
break;
case DOG:
break;
}
As for the images, yes, if they have the same pixel dimensions, their memory footprints will be the same. Whether they get put in the same memory slot depends on what other memory is free at the time, so no, it doesn't guarantee you to avoid fragmentation.
Graham.