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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:07:34+00:00 2026-05-30T05:07:34+00:00

I ran into some Java code at work today : public interface A {

  • 0

I ran into some Java code at work today :

public interface A {

    public static interface AObj {
         String toXml();
         int getCode();
    }

    public static interface AMap {
         String toXml();
         int blah();
    }
    ...
}

I have not encountered having static interfaces embedded in an existing interface before. It doesn’t make much sense. Can someone comment on :

a) Is this good design practice
b) What the benefits are to this vs Having individual interface files.
c) This was written by a c++ programmer, i get the impression they’re trying to re-create namespaces. If that’s the case, why not just use packages ?

Any comments most welcome.

Regards,
Alistair.

  • 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-30T05:07:36+00:00Added an answer on May 30, 2026 at 5:07 am

    Good/bad practice can be debatable. Typically one would nest interfaces if the nested interface is an inseparable entity in relation to its parent.

    Take a look at the source code of java.util.Map. It merrily embeds Map.Entry inside it. The author is Josh Bloch, who is definitely not an inexperienced Java developer. So I’m sure there must be a valid reasoning behind designing the interface that way.

    Here is what it looks like (JavaDoc and comments stripped).

    public interface Map<K,V> {
        int size();
        boolean isEmpty();
        boolean containsKey(Object key);
        boolean containsValue(Object value);
        V get(Object key);
        V put(K key, V value);
        V remove(Object key);
        void putAll(Map<? extends K, ? extends V> m);
        void clear();
        Set<K> keySet();
        Collection<V> values();
        Set<Map.Entry<K, V>> entrySet();
    
        interface Entry<K,V> {
            K getKey();
            V getValue();
            V setValue(V value);
            boolean equals(Object o);
            int hashCode();
        }
    
        boolean equals(Object o);
        int hashCode();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm porting some Java code to C#, and I ran into this idiom used
I just ran into some code that overuse semicolons, or use semicolon for different
i'm writing some stuff in java and i ran into some problems lately. cut
I'm writing my own software rasterizer in Java, and I ran into some trouble
I was looking over some C++ code and I ran into this memcpy function.
I ran into some code I couldn't find an answer to on Google or
I've just started with opengl but I ran into some strange behaviour. Below I
(this is regarding the Ramaze.net framework) I ran into some really strange problems while
I was doing some performance metrics and I ran into something that seems quite
I'm trying to create some HtmlHelper extensions and ran into a bit of a

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.