Abstract Java enumeration
•
Java
I write a library that should rely on enumeration, but the actual Enumeration should be defined by the user of my library
In the following example, the authorization method needs to enumerate parameters of type permission
acl.authorize(userX,Permission.READ,Permission.WRITE)
My library should be able to handle arbitrary permissions defined by the library user However, without permission to enumerate, I cannot compile my library So I need something similar
abstract enum Permission
Is there a way to solve this problem in my library?
Solution
I'll use enumeration and then implement the interface Things along the line
public interface PermissionType{}
This will be used, for example The client defines an enumeration, such as
public enum Permission implements PermissionType [...]
Then your API will accept parameters using the permissiontype type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码