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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:21:23+00:00 2026-05-12T08:21:23+00:00

Assuming I have a class like public class FooImpl { public void bar(){}; }

  • 0

Assuming I have a class like

public class FooImpl
{
    public void bar(){};
}

Is there a way to create its interface at runtime?

e.g.

public interface Foo
{
    public void bar();
}

I have been looking into Javasssist and the truth is it’s reflection that I’m interested in using the interface for (as Esko Luontola and Yishai stated)

So I want an interface that specifies a subset of the original class’ methods to make a proxy from.

I came to realize there are more things to be concerned about like

  • Should you reuse that interface or create a new one each time?
  • The proxy class is effectively a new instance of type java.lang.reflect.Proxy, which might cause implications depending on the use case.

The last point made me wonder on how some frameworks manage to handle this, do they deep copy the object? do they encapsulate the proxy inside the original instance?

So maybe it’s just easier (though maybe not as elegant) to require for the client code to create the interface for the class.

  • 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-12T08:21:23+00:00Added an answer on May 12, 2026 at 8:21 am

    You can do it with some bytecode manipulation/generation during class loading, for example using ASM, Javassist or similar, maybe also AspectJ.

    The important question is, why would you need to do that? No normal code can use the class through its interface, because the interface does not exist at compile time. You would either need to generate the code that uses the interface or use reflection – but in that case you might as well use the original class. And for the interface to be useful, you should probably also modify the original class so that it implements the generated interface (this can be done with the libraries I mentioned).

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You actually have two problems. The first problem is that… May 12, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer Did you try to define both properties as keys? Not… May 12, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer Actually problem is not related to z-index at all. It's… May 12, 2026 at 1:14 pm

Related Questions

I'm working on my first java struts2 webapp and want to be able to
Hope I'm asking this correctly: I have a project Projects.Client I have my class
I am new to EJB3 and am missing something when it comes to accessing
I want to ask a question about how you would approach a simple object-oriented
Upon reviewing a bunch of MVC style web applications, I'm noticing that it's common

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.