represent identifier hierarchy - java
I have a need to have XYZIdentifier object which will be used in composition in other class to identify the object.
However, Depending on the use-case (a variable in the client object), the identifier can be either a String, long, or even a Class.
Something like IntegerIdentifier, StringIdentifier, FooIdentifier and some interface defined which can be generic.
How can I create th开发者_如何学Pythonis design?
Not sure what your full context is, but part of the solution may involve generics to fetch the kind of result you need, like:
public <T extends IdentifierBase> T getIdentifier(Class<T> kindYouWant) { ... }
The idea being you tell it which flavor you need, and it could either convert with best-effort, or return Null if that kind isn's available.
Like I said, not sure of your whole question...
精彩评论