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 8504209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:57:51+00:00 2026-06-11T01:57:51+00:00

I want to ask if there is a possible way to conditionally implement interfaces

  • 0

I want to ask if there is a possible way to conditionally implement interfaces or if there can be a workaround to what I want to do. I want to make two interfaces LangA and LangB that will only hold a very large number of final variables that are Strings used to print messages. As you probably imagine LangA is one language and LangB another one. What I want is have my message-handling class conditionally implement the interface needed based on the system’s locale. I have no idea if this is possible at all in any way even with some custom ibrary, so if not, explain me if it can be worked around at least. (Quick question: is this possible in Scala? thanks!)
I have thought of a possible, but maybe not a very resource-efficient workaraound, which will have the class’s constructor check the locale and set its own finals based on the values of some methodless class that will only feature the finals for each language (e.g. constructor learns that locale is locA so it sets finals myF1=LangA.myF1; myF2=LangB.myF2; etc.) Thanks in advance!

  • 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-11T01:57:52+00:00Added an answer on June 11, 2026 at 1:57 am

    No, this is not possible.

    The “class X implements interface Y” relationship is fixed at compile time, and cannot be altered at runtime.

    However, using interfaces to import constants into a class is a solution that dates back to Java 1.0. This anti-pattern should not be used for new development.

    Moreover, localization with compile-time constants is not a native solution in Java. You should localize using resource bundles.

    If you need a way to switch implementations at runtime, replace constants with methods in your interface, and provide implementations that return different constants:

     interface Constants {
         double getAccelerationDueToGravity();
     }
    
     class EarthConstants implements Constants {
         double getAccelerationDueToGravity() {
             return 9.8;
         }
     }
    
     class MarsConstants implements Constants {
         double getAccelerationDueToGravity() {
             return 3.71;
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to ask if there is any PHP/MySQL datatype that can store
I want to ask question is there possible way with jQuery to change a
Hi want to ask if there is a way to do this without foreach
I want to ask if is there any faster method how to make this
I want to ask pro developers out there that how they manage a big
As a beginner programmer, I want to ask is there any way to using
I don't know if its possible but just want to ask if we can
I don't think that what I want to do is possible, but there are
want to ask user to input something but not want to wait forever. There
I want to ask you something. I make the application web with the Google

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.