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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:26:21+00:00 2026-05-30T20:26:21+00:00

Is there a standard Java interface with a getName() method that returns a string?

  • 0

Is there a standard Java interface with a getName() method that returns a string? I keep finding I have to make my own:

/** objects which know their own names, 
 *  e.g. that are indexed in a Map by their name
 */
interface NamedObject
{
   public String getName()
}

but I’d much rather use a standard one if it’s out there.


edit for an example — which I think is somewhat of a red herring to my question, so I specifically do not want answers suggesting alternatives that are specific to the following situation. (I’ve run into the need for a NamedObject interface several times, so I was hoping it was something in a standard library.)

But since you asked for some background context, here it is:

@Override public void stateChanged(ChangeEvent e) {
    Object obj = e.getSource();             
    if (obj instanceof NamedObject)
    {
        String name = ((NamedObject)obj).getName();
        /* do something based on object's name */
    }
}

In my current project, I have a system with three elements: a source, a transmission method, and a receiver. I want to get some information from the source to a receiver, and I control the implementation of both. The transmission method unfortunately is stuck using an object that supports ChangeListener, so all the receiver gets a ChangeEvent with which I can get a source object.

So I have to use implied shared semantics between my source and receiver, i.e. there’s a shared understanding that the source object passed in the ChangeEvent is of class X, where I can pick class X. In this case, all I really care about is the name, from which I can get additional data. I can define my own interface, I was just hoping to be able to use a standard interface since the source and receiver are in different .jar files…

  • 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-30T20:26:22+00:00Added an answer on May 30, 2026 at 8:26 pm

    As far as I know, not in the Java SE API.

    It is debatable whether a generic NamedObject interface makes sense. Consider for example a Person class and a UnixNamedPipe class. Both could share the same NamedObject interface, but their names actually have vastly different semantics. I can’t see for example a case where it would make sense to have a Collection<NamedObject> with both Persons and UnixNamedPipes.

    It would make sense to define such an interface if you have PetCat, PetDog and maybe PetRock classes. But then you will probably have a Pet super class that already defines getName() for all pets. In this case, what the concept of what a “name” is will not change from one pet to another.

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

Sidebar

Related Questions

Is there a standard Java library that handles common file operations such as moving/copying
Is there an object within the standard Java SE that can accept a HTTP
Are there any standard generic callback or function/method types in Java, like System.Action<T> or
I have a class that implements the Enumeration<T> interface, but Java's foreach loop requires
Is there a standard interface that can be implemented by beans supporting registration of
Is there a list of standard marker interfaces in Java? I've read (in some
Is there a standard Java (1.5+) implementation (i.e. no 3rd party) of a collection
Is there some standard email validator code sample for Java ME or BlackBerry?
Is there a Java equivalent to .NET's App.Config? If not is there a standard
Is there a standard/good way of converting between urls and windows filenames, in Java?

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.