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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:34:09+00:00 2026-05-26T16:34:09+00:00

This question concerns the reflection mechanisms of the java programming language. I have an

  • 0

This question concerns the reflection mechanisms of the java programming language.

I have an interface:

package A;

public interface MyInterface {

    public boolean doSomething(Object... parameters);
}

I have several implementation classes for this interface. Here some examples:

package B;
import A.*;

abstract class BaseImplementation implements MyInterface {

    private Object field;

    protected BaseImplementation() {

        super();
    }

    public void setField(Object aField) {

        field = aField;
    }

    public Object getField() {

        return field;
    }
}

package B;
import A.*;

public class ConcreteImplementation extends BaseImplementation {

    public ConcreteImplementation() {

        super();
    }

    ...

    // The concrete implementation provides an implementation for all
    // inherited abstract methods. Apart from this no other methods
    // are overridden.
    // This concrete class provides accessor methods for all of its own
    // private fields.

    ...
}

(edited) As a sidenote (this may not be relevant to the issue concerning the reflection mechanism):

I’m implementing a complex ruleset. One drawback of this ruleset is that there are lots of interdependencies between objects. Thus there is a need to define the general behaviour with interfaces. When implementing one part of the ruleset you have to consider the behaviour of another, not yet implemented, part.

Different implementations of an interface require different resources/objects to work properly. To reduce duplicate code I use the abstract parent classes. These abstract classes are not used outside of their packages.

When instantiating and initializing an instance of a concrete implementation class I resort to reflection mechanisms. For this purpose I have a utility class (which resides in a separate package) where I have to specify the desired classname, which field gets which value (i.e. the appropriate setter methods will be looked up then) and the order in which the setter methods are called.

I have two different development environments and on each a different version of java is installed (1.5.x and 1.6.x). This is mainly used for cross checking the behaviour of the implementation.

Instantiating an instance of a concrete implementation class works in both environments. But the
initialization fails with the older java version. Somehow the public setter method of the base class (the base class has a default visibility) cannot be accessed. The newer java version has no issues with accessing the setter method.

One workaround I found is to change the visibility of the base class (default -> public). The question is, is there a way to keep the visibility (default) and still call the setter method with reflection mechanisms?

  • 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-26T16:34:09+00:00Added an answer on May 26, 2026 at 4:34 pm

    Depending on what security restrictions you have in place you can use

    AccessibleObject.setAccessible(boolean);
    

    (AccessibleObject is an interface implemented by Field, Method, Constructor). Before your reflections call just invoke method.setAccessible(true); on the reflections object and unless the SecurityManager throws an Exception you should be fine.

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

Sidebar

Related Questions

This question concerns memory in Android. My method: I have two activites, A and
I have a question that is similar to this question , but mine concerns
This question was very helpful, however I have a list control in my report,
This question concerns running python files in terminal that are not stored in the
I am using Sqlite3 with Flask microframework, but this question concerns only the Sqlite
My question concerns the output of this statement: for x in range(4), y in
This question concerns generics and types as well as datatables. The following snippet is
This question is language agnostic but I am a C# guy so I use
This is a conceptual question but I think it does have an 'answer', hopefully
(The following question concerns the OCaml language and has examples in OCaml, but the

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.