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 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

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I generally just have 6 boxes set up. 2 each… May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer Private set on myName means you can only initialize (set)… May 12, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer I like this pattern for programmatically selecting a record on… May 12, 2026 at 1:10 am

Related Questions

Back in the old days, Help was not trivial but possible: generate some funky
We develop custom survey web sites and I am looking for a way to
I am looking for a WinForms treeview control with following requirements: Should be not
I have been looking for a collaborative tool for developing functional specifications. I am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.