Is that possible to write our own marker interface in java. I am writing a code like
public interface MyMarker {
}
Is that a marker interface?
If it is possible then how can I let JVM know that this interface is my own created marker interface?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, that’s a marker interface. You would test whether an object “implemented” it as simply as:
For a particular class (instead of object) you’d want
You should consider using annotations instead of marker interfaces though. They’re not always direct replacements, but in many cases they’re used for the same goals, and annotations are (IMO) cleaner.