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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:57:51+00:00 2026-06-03T19:57:51+00:00

I have 3 projects in my workspace – A, B, and C which is

  • 0

I have 3 projects in my workspace – A, B, and C which is an Android lib project.

  1. A contains an Activity named Atest
  2. B contains a class named Btest which implements interface I.
  3. C contains the I interface.

Both A and B are installed on my Android device.
During Atest runtime, i’m executing the next code:

Context otherContext = createPackageContext("com.package.b",
                CONTEXT_INCLUDE_CODE | CONTEXT_IGNORE_SECURITY);
ClassLoader loader = otherContext.getClassLoader();
Class<?> btest = Class.forName("com.package.b.BTest", true, loader);

Now here is my question – is there any way to cast btest into I within A run context?

I’ve tried many obvious (and several not-so-obvious) tricks, and nothing worked for me. I can of-course explore btest’s methods and interfaces, invoke its methods, etc.. but I simply can’t cast it into I, although both A and B referring the exact same I interface in lib-project C.

Thanks in advance!

P.S.

Kindly note that I’m casting it into an interface, not into an object, so I guess different ClassLoader isn’t the reason in this case.

  • 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-06-03T19:57:53+00:00Added an answer on June 3, 2026 at 7:57 pm

    Because you are doing all of this dynamic loading at run time there is no construction of a virtual method table and its associated vpointers. Therefore there no way for the runtime to dynamically dispatch calls to the interface methods to the appropriately loaded implementation. You have to use reflection.

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

Sidebar

Related Questions

I have 2 projects. One project is a core and contains the GUI which
I have several projects open in an Eclipse workspace. Like so: com.harbl.project.one com.harbl.project.two com.harbl.project.three
I have 3 projects in a VS6 workspace. One is the main program, which
I have 5-6 projects in my workspace, many of which are interdependent. I usually
I have two projects in a workspace, which I have under SVC (Subversion control),
I have several dynamic web projects in my workspace, each contains classes and refers
I have 2 Maven projects in Eclipse workspace, A and B. Project B is
We all can import an existing Android project into workspace using File->Import->Existing projects into
I have a workspace with a bunch of java projects. If I go to
I have close to about 20 projects in my Eclipse workspace. They are interdependent.

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.