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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:43:29+00:00 2026-05-25T12:43:29+00:00

Using a java.lang.reflect.Proxy , I can create a class that takes an InvocationHandler as

  • 0

Using a java.lang.reflect.Proxy, I can create a class that takes an InvocationHandler as constructor argument. However, the class will be instantiated via newInstance() somewhere in the framework, and the InvocationHandler can be the same for all instances.

Can I add a no-arg constructor to the proxy class, which passes my InvocationHandler to the original constructor?

  • 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-25T12:43:30+00:00Added an answer on May 25, 2026 at 12:43 pm

    I’m afraid it won’t work hat way, as the actual proxy magic happens in this native code

    private static native Class defineClass0(ClassLoader loader, String name,
                         byte[] b, int off, int len);
    

    that’s only accessed through the static Method Proxy.newProxyInstance(ClassLoader, Class<?>[], InvocationHandler). This method in turn calls the constructor of the thusly generated class with the supplied InvocationHandler as parameter.

    So there’s no way for you to return a Proxy from a newInstance() call. The closest you can get is to instantiate the InvocationHandler with newInstance() and pass it to the static factory method.

    Or you could take the whole thing one step further, have a Class that implements he target interface(s), constructs a proxy field through the factory method and delegates all interface methods to the Proxy. But that would be a proxy around a proxy, and I really don’t see the point of that.

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

Sidebar

Related Questions

my problem is that, i want to save class object java.lang.reflect.Field into database using
At what point would you create your own exception class vs. using java.lang.Exception? (All
Using Java, how can I test that a URL is contactable, and returns a
In order to avoid Java exceptions I'm using Scala's exception handling class. However, when
I get the following warning when using java.net.URLEncoder.encode : warning: [deprecation] encode(java.lang.String) in java.net.URLEncoder
What is the easiest way to test (using reflection), whether given method (i.e. java.lang.Method
Using Java (1.6) I want to split an input string that has components of
By using java reflection, we can easily know if an object is an array.
I'm using JBOSS Seam 2.0 with JBoss 6 to send emails. I'm getting java.lang.UnsupportedOperationException
I'm using MPlayer in my java application. According to its doc, it's needed that

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.