Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:29:45+00:00 2026-06-10T08:29:45+00:00

I’d like to know if it’s possible to force an interface to be implemented

  • 0

I’d like to know if it’s possible to force an interface to be implemented by an enum.

I have the following interface:

public interface MobileApplication {
    String name();
}

This should be implemented by an enum because i need garantee on the uniqueness of the name.
As i am designing a library i can’t trust the library users, and without an unique name, my library will not work at all.

I can do without with security, just wonder if it’s possible.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:29:47+00:00Added an answer on June 10, 2026 at 8:29 am

    Unfortunately you can’t really do this at compile-time. You can give hints at this by requiring methods like ordinal() and name() or you can check it at runtime.

    Regarding "I can’t trust the library users": as long as you document the requirement in the interfaces JavaDoc, anyone who doesn’t follow it gets what they paid for.

    That’s exactly the same as if someone didn’t implement equals() and hashCode() correctly: the compiler doesn’t enforce it, but if you break it, then classes that depend on them break as well.

    The closest you can get is probably something like this:

    public interface EnumInterface<E extends Enum<E>> {
    }
    

    where the implementation would look like this:

    public enum MyInterfaceImpl implements EnumInterface<MyInterfaceImpl> {
      FOO,
      BAR;
    }
    

    It’s just another hint, since a "malicious" developer could still build a class like this:

    class NotAnEnum implements EnumInterface<MyInterfaceImpl> {
    }
    

    All in all, there will always be ways to mis-use any library. The library authors goal is to make it easier to use the library correctly than it is to use the library incorrectly. You don’t need to make it impossible to use it incorrectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.