In Objective C, to declare a variable constant I use #define FILE_NAME @"file.data"
in a file called Constants.h. I import this file when needed.
What is the Java equivalent?
In Objective C, to declare a variable constant I use #define FILE_NAME @"file.data"
in a file called Constants.h. I import this file when needed.
What is the Java equivalent?
A constant in Java is the following
public static final String FILE_NAME = "file.data";
There is no Java equivalent to the C #define
because there is no Java pre-processor. But you can define constants in Java. Inside a class, say Constants
public static final String FILE_NAME = "file.data";
Then you can perform a static import in another class where you need the constant:
import static my.package.Constants.*;
...
doSomethingWithFile(FILE_NAME);