Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(condition){
- public static final test = "some value";
- }
- public class Test {
- public static final String test;
- static {
- String tmp = null;
- if (condition) {
- tmp = "ss";
- }
- test = tmp;
- }
- }
- public static final String test = condition ? "value" : "other value";
- public enum Const {
- SAMPLE_1(10), SAMPLE_2(10, 20);
- private int value1, value2;
- private Const(int value1, int value2) {
- this.value1 = value1;
- this.value2 = value2;
- }
- private Const(int value1) {
- this.value1 = value1;
- }
- //Value based on condition
- public int getValue(boolean condition) {
- return condition == true ? value2 : value1;
- }
- //value which is not based on conditions
- public int getValue() {
- return value1;
- }
- }
- public interface InitializeInInterface {
- public static final String test = Initializer.init();
- static class Initializer {
- public static String init() {
- String result = "default value";
- InputStream is = InitializeInInterface.class.getClassLoader().getResourceAsStream("config.properties");
- Properties properties = new Properties();
- try {
- properties.load(is);
- } catch (IOException e) {
- e.printStackTrace();
- }
- if ("bar".equals(properties.getProperty("foo"))) {
- result = "some value";
- }
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment