Trying to understand what it is in java. method? Thank you
static {
String xxx;
try {
xxx = new File(".").getCanonicalPath();
} catch (final IOException e) {
e.printStackTrace();
xxx = ".";
}
Trying to understand what it is in java. method? Thank you
static {
String xxx;
try {
xxx = new File(".").getCanonicalPath();
} catch (final IOException e) {
e.printStackTrace();
xxx = ".";
}
In this situation, static indicates that the block should be executed once only, prior to the first instance of the class being constructed.
Your example is not particularly useful in itself, as the String xxx
will go out of scope at the end of the static block. I assume that there is other code that you have not shown that does something with this variable.