Last active
August 14, 2019 03:38
-
-
Save RoboMWM/189fdd97bc66572ff9fea5d1af5fdad2 to your computer and use it in GitHub Desktop.
Playing with generics in java. A simple test of something implemented in https://github.com/AuthMe/ConfigMe. IMO, it's ok, but kinda results in the same effect as defining a method - since you have to specify the node's path as a string anyways. I guess it does save a little in the amount of lines per node. UPDATE: Ok I'm learning generics and I…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Property<T> | |
{ | |
T value; | |
String key; | |
Property(String key, T value) | |
{ | |
this.key = key; | |
this.value = value; | |
} | |
T getValue() | |
{ | |
return value; | |
} | |
} | |
class ConfigNodesThing | |
{ | |
public static Property<String> errorMessage = new Property<>("hello", "blah"); | |
public static Property<Integer> errorInt = new Property<>("hello2", 5); | |
} | |
class ConfigManagerThing | |
{ | |
static Map<String, Object> config = new HashMap<>(); | |
static <T> T getValue(Property<T> thing) | |
{ | |
return (T)config.get(thing.key); | |
} | |
} | |
class WhoCares | |
{ | |
String whatever() | |
{ | |
return ConfigManagerThing.getValue(ConfigNodesThing.errorMessage); | |
} | |
int nobody() | |
{ | |
return ConfigManagerThing.getValue(ConfigNodesThing.errorMessage); //error | |
} | |
int cares() | |
{ | |
return ConfigManagerThing.getValue(ConfigNodesThing.errorInt); | |
} | |
String ok() | |
{ | |
return ConfigManagerThing.getValue(ConfigNodesThing.errorInt); //error | |
} | |
String boo() | |
{ | |
return ConfigNodesThing.errorMessage.getValue(); | |
} | |
String hoo() | |
{ | |
return ConfigNodesThing.errorInt.getValue(); //error | |
} | |
} |
Author
RoboMWM
commented
Aug 14, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment