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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:30:46+00:00 2026-05-11T09:30:46+00:00

I am looking to provide some convenience through reflection to programmers who will be

  • 0

I am looking to provide some convenience through reflection to programmers who will be using my code. To achieve my desired result I would like to get the class object for classes that extend my code. Even though they can’t override the static method I wish to access the information from, it would be currently helpful. I may end up simply refactoring the design a bit to avoid this situation, but wanted to toss this question out to the community.

The only way to achieve this that I am aware of is to take the current thread, navigate the stack trace, and extract the class name, then convert that into an actual instance of the class.

Any other suggestions?

Side note: the above approach is also the only way that I’m aware of getting the calling method.

  • 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. 2026-05-11T09:30:47+00:00Added an answer on May 11, 2026 at 9:30 am

    When in the static method, what is the guarantee that some (any) class that has been extended from yours is on the stack?

    If you think about this a little, I suspect you will realize what you are looking for does not exist.

    /EDIT 1/ I think what you need is

    abstract class B {     <T extends B> B create(Class<T> clazz) {     .... } 

    Hmmm. What if create is protected method? Then you could be pretty sure the caller is a B, you can even require that, throwing UnsupportedOperation or IllegalState if the caller is not assignable to B.

    You can use Thread.currentThread().getStackTrace()

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

Sidebar

Related Questions

I'm looking for someone who can provide some information on analytics for an intranet
I'm looking into using Lucene and/or Solr to provide search in an RDBMS-powered web
I'm looking for a place to hook some code to programmatically create, size and
I'm looking to outsource some of my work to a decent library. I'll provide
We are looking to provide two custom Platform switches (the platform dropdown in the
I'm looking for the best way to provide authorization, authentication, and auditing to web
I'm looking at moving my application from using active directory membership provider to using
Looking for feedback on : http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
I'm currently working on a plug-in for Eclipse that translates some custom Java code
I am looking for some ASP.NET Ajax Controls (similar to those by Telerik )

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.