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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:22:36+00:00 2026-06-12T04:22:36+00:00

I am developing a largish hierarchy of Java classes, some of which have a

  • 0

I am developing a largish hierarchy of Java classes, some of which have a particular property that I am interested in querying at runtime (the property definitely only applies to classes, not specific instances).

I could create an abstract boolean method isFooBar() that subclasses could implement to indicate whether the property is present or not:

public abstract class MyBaseClass {
  ...
  public abstract boolean isFooBar();
}

Or alternatively I could use a marker interface FooBarProperty and do an instanceof check against the interface:

public class MyConcreteClass extends MyBaseClass implements FooBarProperty {
   ...
}

Or I guess you could even use an annotation as suggested by AmitD:

@FooBarAnnotation
public class MyConcreteClass extends MyBaseClass {
   ...
}

What are the pros and cons of each method, and which should normally be preferred?

  • 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-12T04:22:38+00:00Added an answer on June 12, 2026 at 4:22 am

    Marker interfaces are inherited in class hierarchy, so they have limited capabilities (you cannot “remove” this marker interface for some particular subclass) and I cannot recommend them (Cloneable is a bad example of this). The question is – is your property really bound to object’s class, not to instance? If so, annotations are better, because they don’t add additional methods into your APIs and they are easier to maintain – you just add/remove the annotation (in case of checking method, you have to check all the subclasses, whether they override it or not).

    EDIT: in your case, I would ask myself question: is my property like ‘is persistent’ (applies for all instances of given class) or ‘is visible’ (applies only for some instances)

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

Sidebar

Related Questions

Developing Java, you have always learned that its best to create an ArrayList by
Developing a project of mine I realize I have a need for some level
I am developing a Java application using Google App Engine that depends on a
Developing a series of POCOs on my project, and just realized that some of
Developing for iPhone, I have a collection of points that I need to make
Developing a network application, I have a Connection class that manages sending and receiving
Developing an application, In which I have many user's account_id(skype id), Now what I
Currently developing an Outlook add-in with Add-in Express, I have to revert to some
Does Java 6 consume more memory than you expect for largish applications? I have
Im developing a webapp that is feeded via a server. Its index presents some

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.