In Java, is there a type constant equivalent to Pascal
In Delphi / Pascal, there is a mechanism through which local variables in a method can remember the value from one method call to the next method This is done using type constants For example:
procedure blah(); const i: integer = 0; begin i := i + 1; writeln(i); end;
Every time I call blah (), I add The output results are as follows:
1 2 3 4 5
(each number is on a different line, but the editor places them on the same line)
Does java have the same thing?
Solution
The closest equivalent in Java is the static variable of a class It has a static life cycle, but it also has a wider range than Delphi allocable type constants
In Java, nothing has oddly named allocable type constants like Delphi. They have local scope but static life cycle Static class variables are as close as possible
In C / C + +, you can use a local variable with static storage duration, which has the same semantics as Delphi's allocable type constant