I am new to Java, and have inherited an existing android app. The original developer has chosen to use an Interface for Constants.
My problem is that I need to change a number of these constants to compile the App for Production vs Dev. Everything works just fine if I modify a handful of values by hand, but that is just an ugly way to handle this, and I will probably make a mistake one day.
So, my goal is to find a solution that can be transparent to the remainder of the code, and use a single Constant to toggle back and forth between dev and production.
Sample of existing Code:
package package.common;
public interface Consts {
// Define the Build Type
boolean PRODUCTION_BUILD = false;
String BASE_URL = "https://domain.com/Dev/Mobile.ashx";
interface RSA {
String PUBLIC_KEY_SHA1 = "....";
}
}
and used like this
import package.common.Consts;
public class HttpsConn extends NetConnection {
String url = Consts.BASE_URL;
}
Is there a way to use a CONSTANT to modify this Interface at compile time? Or am I going to have to bit the bullet and modify the code that uses this interface as part of the solution?
No, but you can write this in
Consts