If you tried to initialize a final variable within a try block, you would get a compile-time error.
Here's an example class:
class Example {
private final String example;
public Example() {
try {
example = "Example";
} catch (Exception e) {
// Just an example.
}
}
}
Obviously you wouldn't need to try-catch something like this (it's a stupid example - I know) , but the point is, the code wouldn't compile, and would return an error saying something like "example may not have been initialized".
So I've got two questions. Why is this, and is there any way around it?
Thanks in advance :)