Visibility of named inner classes

Discussions

General J2EE: Visibility of named inner classes

  1. Visibility of named inner classes (7 messages)

    I'm working on a design for a RowSet based DTO and I was wanting to group constants up in a named inner class that the main class could expose. Something like the code below. This works fine within the package, but when I try to reference any of the constants outside the package, I get a compile time error "Field is not visible". Is it possible to do this (without making all the constant classes full blown public classes)?

    A reference like below works within the UserRowSet package, but not outside it:
      UserRowset.RESULT_COLUMNS.USERID;


    public class UserRowSet extends CachedRowSet{
        public static final RESULT_COLUMNS = new UserRowSet().new QueryColumns();

        // class impl
        class ResultColumns{
           public static final String USERID = "USERID";
           public static final String FIRSTNAME = "FIRSTNAME";
        }
    }

    Threaded Messages (7)

  2. Visibility of named inner classes[ Go to top ]

    Make the innner class public i.e.

    public class ResultColumns {...}

    Dmitriy.
  3. I mean it still should be inner class.
  4. Visibility of named inner classes[ Go to top ]

    That works. For some reason, I thought you could not declare public inner classes. Thanks.
  5. Visibility of named inner classes[ Go to top ]

    You are welcome.

    Dmitriy.
  6. Visibility of named inner classes[ Go to top ]

    Dmitriy,John
        Is there any vantage , when we put all the constants into a public inner class ? instead of using an interface or a static class???
  7. Visibility of named inner classes[ Go to top ]

    I would personally use standalone pubplic class.

    D.
  8. Visibility of named inner classes[ Go to top ]

    any specific reason ? instead of an interface ?

    Sri