New to Java, but I've done some .Net programming. I'm wondering if Java has the equivalent of a .Net eum? Below is an example. I know Java has enum, but you can't assign values to it.
In .Net I could do an enum with values. When used in code I don't have to comment or, when writing new procedures, remember what 0, 1, 2, and 3 represent. I could also use the enum as parameter type in a constructor and then pass AccessType.Full, for instance, in as an argument.
How can I duplicate this is Android Studio?
Public Class Delete
Private Enum AccessType
Full = 0
ReadOnly = 1
Delete = 2
Add = 3
End Enum
Private Sub DeleteIem(sItem As String)
If User.Access = AccessType.Delete Or User.Access = AccessType.Full Then
'delete something here
Else
MsgBox("You do not have access to delete these items.", vbInformation
End If
End Sub
End Class
In Android Studio I have the if{} block below.
if (AllLists.get(pos).Access == 0) {
MsgText += getResources().getString(R.string.info_cat_shared_no) + "\n";
}
else if (AllLists.get(pos).Access == 1){
MsgText += getResources().getString(R.string.info_cat_shared_edit) + "\n";
}
else if (AllLists.get(pos).Access == 2){
MsgText += getResources().getString(R.string.info_cat_shared_no_edit) + "\n";
}
It would turn the code in to below and I wouldn't have to always be checking what 0, 1 ,2, & 3 represent. I looked up Java enums and they are just a list of string, which doesn't work for this, or at least not that I can think to implement it.
if (AllLists.get(pos).Access == AccessType.Full) {
MsgText += getResources().getString(R.string.info_cat_shared_no) + "\n";
}
else if (AllLists.get(pos).Access == AccessType.ReadOnly){
MsgText += getResources().getString(R.string.info_cat_shared_edit) + "\n";
}
else if (AllLists.get(pos).Access == AccessType.Delete){
MsgText += getResources().getString(R.string.info_cat_shared_no_edit) + "\n";
}