I am working on some code that looks to check and see if a person is already enrolled on a course.
As part of this activity I wrote a new class that contains a CourseMembership object to hold details of the membership if it exists.
When a new instance of this class is created, I originally set the CourseMembership.Role value to CourseMembership.Role.NONE - i.e. one of the standard enumerated types. I thought this was a sensible choice. It turns out it is not. Looking at the CourseMembership class, it looks like this has been defined as an alias of CourseMembership.Role.STUDENT. Thus effectively: CourseMembership.Role.STUDENT == CourseMembership.Role.NONE
As such any test to see if the CourseMembership value in my custom class had a role of STUDENT returned true even if it was actually assigned the value CourseMembership.Role.NONE
I would caution other developers not to interpret the role of CourseMembership.Role.NONE as having no role :-)
Hope that saves other people from the head scratching that debugging this behaviour called :-)