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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:34:22+00:00 2026-06-12T15:34:22+00:00

I need to create an element repository for my app. This is the class

  • 0

I need to create an element repository for my app.

This is the class I created.

public class Elements
{
  public enum Type1
  {
    A    ("text1"),
    B    ("text2"),
    C    ("text3"),
    D    ("text4"),
    E    ("text5");

    private String identifier;

    Type1(String identifier)
    {
      this.identifier = identifier;
    }

    getPath()
    {
      String path = "";
      //do something
      return path;
    }
  }
}

Now I can access the values using Elements.type1.A.getPath();

I did a static import of Elements.type1 and I want to remove the usage of getPath() because it would complicate my code. ie. I need to be able to use type1.A.

So I did,

public class Elements
{
  public enum Type1
  {
    A
      {
        public String toString()
        {
          return getPath("text1");
        }
      },
    B
      {
        public String toString()
        {
          return getPath("text2");
        }
      },
    C
      {
        public String toString()
        {
          return getPath("text3");
        }
      };

    Type1() {}
  }
}

Now I can use Elements.Type1.A with print statements but I have a method which accepts String as parameter.

So that makes it Elements.Type1.A.toString(). Without toString(), it throws an error.

Is there a method to get rid of toString()?

Edit : New Code

public Interface Type1 
{
   String A = "text1";
   String B = "text2";
   String C = "text3"; 
}
public class Utility 
{
   public static void main(String[] args) 
   {
     getPath(Type1.A); 
   }
   public static void getPath(String arg) 
   { 
    //Constructs xpath - text1 changes to //*[contains(@class,'text1')] 
    return xpath; 
   } 
} 
public class myClass 
{
   public void doSomething() 
   {
     assertEquals(Type1.A,xpath); 
   } 
}

Here, Type1.A returns “text1” and not //*[contains(@class,’text1′)]

  • 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-12T15:34:23+00:00Added an answer on June 12, 2026 at 3:34 pm

    It appears you need three String constants not enums.

    public static final String A = "test1";
    public static final String B = "test2";
    public static final String C = "test3";
    

    Using an interface is not always best, but without further context I can’t suggest something better

    public interface Type1 {
        String A = "test1";
        String B = "test2";
        String C = "test3";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an element from this html string: <li class=station_li> <span class=seq_num></span>
I need to create a class that will store a unique object elements. I
I need to create inline element to control collapsible element. I've created the following:
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create an element with radial glow, like this . But now
I want to create a sequence, however to create its every element I need
If I need to create a couple of nested DOM elements, I know one
I have a Mootools class that creates an element. I need to add a
I have the following code. I need to create list separators before A elements,
I need create clone repository. but I do not know where can I get

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.