I have what most likely is a dumb question regarding thread safety. I have a ENUM class where I have valuesof defined like so:
public enum ThirdPartyContentSource {
DEV_TO("DevTo"),
MEDIUM("Medium"),
HASH_NODE("HashNode");
private String thirdPartyText;
ThirdPartyContentSource(String text) {
this.thirdPartyText = text;
}
public String getText() {
return this.thirdPartyText;
}
public static String valueOfCode(String thirdPartyCode) throws IllegalArgumentException {
ThirdPartyContentSource text = Arrays.stream(ThirdPartyContentSource.values())
.filter(val -> val.name().equals(thirdPartyCode))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unable to resolve ThirdPartyCode: " + thirdPartyCode));
return text.getText();
}
}
my question is, if two threads call the the valueOfCode() method at the same time is there any thread safety concerns?
Many thanks