I need a simple enum
declaring the Java reference types, as:
public enum ReferenceType {
STRONG, SOFT, WEAK, PHANTOM;
}
Does such enum
exist somewhere in the Java API or a general utility library such as Guava ? I have not been able to find it in either place, although I found third party projects that declare it (e.g. google-guice: RefrenceType).
I just try to avoid polluting my project with silly classes/enums that may exist somewhere else.
Since asking this question, I found that Guava in fact used to have this, but they dropped it: Issue 1662: Feature request for enum of reference types
1
You can find one in hibernate
ReferenceType though it only contains STRONG, SOFT and WEAK but not PHANTOM.
There are few others ReferenceType in eclipse net4j and Link.Type in true commons. But I think you will be better without them in case you want some modification later.
Think in terms of code polution
- 10-liner
vs
- project just included to use a 10-liner.
1
No it wont exist mostly because enums are itself available in their most simplified form in java.lang package and can be used as per the user’s wishes. So even if there will be an API for enum, it won’t be of much help
For further reading on enums go to
http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
1