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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:55:59+00:00 2026-06-17T12:55:59+00:00

What I’m trying to achieve is a nice abstraction for my database tables. The

  • 0

What I’m trying to achieve is a nice abstraction for my database tables. The result I’m looking for is to be able to do this:

System.out.println(Table.Appointment);    // prints the name of the table 
System.out.println(Table.Appointment.ID); // prints the name of the column

Here is what I’ve come close with, but fields seem to take priority over static inner classes.

public class Table {

    // attempt to allow 'Table.Appointment' to resolve to a String
    public static final Table Appointment = new Table("Appointment");

    // attempt to give access to column names within the table,
    // these class names should be the same as its name field above.
    public static final class Appointment{
        public static final String ID = "AppointmentId";
    };

    private String name; 
    private Table(String name){ this.name = name; }
    public String toString() { return name; }
}

Can this actually be achieved?

  • 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-17T12:56:00+00:00Added an answer on June 17, 2026 at 12:56 pm

    While I strongly discourage what you are doing, simply because it makes your application too solid, this works (Edited to avoid cyclic references.) :

    public final class Table {
    
        // ===== DECLARE YOUR INSTANCES HERE =====
    
        static public final AppointmentTable Appointment = new AppointmentTable();
        // static public final FooTable Foo = new FooTable();
    
        // =======================================
    
        static private abstract class TableImpl {
            public abstract String getTableName();
            public String toString() { return getTableName(); }
        }
    
        // ==== DECLARE YOUR DEFINITIONS BELOW ====
    
        static public class AppointmentTable extends TableImpl {
            public final String ID = "appointmentId";
            // public final <type> <columnName> = <dbFieldName>;
    
            public String getTableName() { return "appointment"; }
            private AppointmentTable() {}
        }
    
        // static public class FooTable extends TableImpl { ... }
    
    }
    

    This is as close as you can get from what you want. Note that users won’t actually see this design, only programmers will… so who cares?

    Also, having access to Table.AppointmentTable is normal. This is how you can access Table.Appointment.ID. But you can’t create an instance of it neither extend it, and it is all good.

    ** Edit **

    Why this limitation? Because you can’t just use a type and treat it as a value. A type defines the container, not the content. And as much as you can’t System.out.println(int); because int is a token (or a type, or a container), you cannot treat a class name as a value that you can echo. Among other things, this is why you have Table.AppointmentTable.class.getSimpleName() (or .getName()).

    You can only work with values. A class definition is not a value, it’s a definition of a container for a value. The variable of that class definition hold the content of that container, from which you can echo or manipulate.

    The same thing goes with unassigned variables. If you try :

    int foo;
    System.out.println(foo);
    

    the compiler will whine about foo not being initialized. This is because declaring a variable does not assign any content to it (you declare a container of type int named foo), does not make it hold any content unless you assign something (contents) to it.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.