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

  • Home
  • SEARCH
  • 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 6937141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:32+00:00 2026-05-27T12:19:32+00:00

I am considering a design in Java where I want a string object but

  • 0

I am considering a design in Java where I want a string object but with more ‘type-safety’ than just being of class String. This because I have a number of ‘POJO’ objects for Hibernate, representing my database tables. Each of these classes has a large number of public static fields representing the properties of the class, I.e.:

public class PersistantBean {
    public static String PROP_FIELD_COLUMN_ONE="columnOne";
    public static String PROP_FIELD_COLUMN_TWO="columnTwo";
    // [...]

These properties are used when we need to access a property in a generic way, e.g. for code I am currently writing .parseAndSet(PROP_FIELD_PRICE,"£3.00").

I would like to be able to add a stronger type to the PROP_FIELD_... fields so that I could write

public class PersistantBean {
    public static PropertyName PROP_FIELD_COLUMN_ONE="columnOne";
    public static PropertyName PROP_FIELD_COLUMN_TWO="columnTwo";
    // [...]

with minimal changes to other parts of the project,

so that parseAndSet would look like:

public void parseAndSet(PropertyName prop, String priceToParse)

Essentially, I would like PropertyName to be a type that is like String in everyway apart from the compiler would error if I tried to put a String where a PropertyName was expected, is any design pattern like this possible.
(I am shying away from Enums, although now I mention it, Enums may be the way to go.)

  • 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-05-27T12:19:32+00:00Added an answer on May 27, 2026 at 12:19 pm

    For Java 1.5 and above, just use an enum type.

    For Java 1.4 and below, use the typesafe enum pattern. E.g.

    public class Suit {
        private final String name;
    
        public static final Suit CLUBS =new Suit("clubs");
        public static final Suit DIAMONDS =new Suit("diamonds");
        public static final Suit HEARTS =new Suit("hearts");
        public static final Suit SPADES =new Suit("spades");    
    
        private Suit(String name){
            this.name =name;
        }
        public String toString(){
            return name;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am considering the design of an interpreter for Python like object oriented language
Just a general database design question - no programming, but a bit of problem
considering good design, is it better for each view controller to manager their own
I'm considering a design for a private messaging system and I need some input
I am considering a design where all fatal exceptions will be handled using a
An upcoming project of mine is considering a design that involves (what I'm calling)
I'm considering the best way to design a permissions system for an admin web
Considering such code: class ToBeTested { public: void doForEach() { for (vector<Contained>::iterator it =
Considering private is the default access modifier for class Members, why is the keyword
Considering this code, can I be absolutely sure that the finally block always executes,

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.