Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. if(condition){
  2. public static final test = "some value";
  3. }
  4.  
  5. public class Test {
  6.  
  7. public static final String test;
  8. static {
  9. String tmp = null;
  10. if (condition) {
  11. tmp = "ss";
  12. }
  13. test = tmp;
  14. }
  15.  
  16. }
  17.  
  18. public static final String test = condition ? "value" : "other value";
  19.  
  20. public enum Const {
  21. SAMPLE_1(10), SAMPLE_2(10, 20);
  22.  
  23. private int value1, value2;
  24. private Const(int value1, int value2) {
  25. this.value1 = value1;
  26. this.value2 = value2;
  27. }
  28.  
  29. private Const(int value1) {
  30. this.value1 = value1;
  31. }
  32.  
  33. //Value based on condition
  34. public int getValue(boolean condition) {
  35. return condition == true ? value2 : value1;
  36. }
  37.  
  38. //value which is not based on conditions
  39. public int getValue() {
  40. return value1;
  41. }
  42. }
  43.  
  44. public interface InitializeInInterface {
  45.  
  46. public static final String test = Initializer.init();
  47.  
  48. static class Initializer {
  49. public static String init() {
  50. String result = "default value";
  51. InputStream is = InitializeInInterface.class.getClassLoader().getResourceAsStream("config.properties");
  52. Properties properties = new Properties();
  53. try {
  54. properties.load(is);
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. }
  58. if ("bar".equals(properties.getProperty("foo"))) {
  59. result = "some value";
  60. }
  61. return result;
  62. }
  63. }
  64. }
Add Comment
Please, Sign In to add comment