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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:51:59+00:00 2026-05-17T19:51:59+00:00

Guys, I have got a slightly different problem with Java Dynamic class loading. I

  • 0

Guys,
I have got a slightly different problem with Java Dynamic class loading. I have to pass an object( lets say Object A1 of class A) to the constructor of a different object B1 of class B, So that the A1’s details are stored inside B1. B1 does not know what kind of object it is receiving. So all it knows is that A1 is an object.

Now I have functions in class B, which accept object C1 and check if it is equal to Object A1. So basically I have to check

  1. If object C1 is also of the type class A. ( Actually I am not past this point. )
  2. If the values inside the objects are the same

I tried a solution :

When storing the Object A1 inside B1 , I also store the name of the class “A” since object B1 only gets the object A1 but not the class name A.


public static void testing(Object C1, String s) //testing is the function of B called by B1
  {
      try{
          Class c = Class.forName(s);

          if( C1 instanceof c) // This is throwing error stating c cannot be resolved to a type
          {
              //further checking
          }


      }catch (Exception e){ System.out.println(e);}
  }

I have been trying different code to get the class type to make a instanceof () comparision but I am not successful . Any suggestion ?

I even tried this but same error


ClassLoader classLoader = B.class.getClassLoader();

      try{
          Class class11 = classLoader.loadClass(s);
          if ( C1 instanceof class11 )
          {

          }
          }catch (Exception e){ System.out.println(e);}

Any pointer on how to proceed would be very helpful !

Solution is to use : isInstance instead of instanceof

There is also other issues attached with this problem . Let me update it with my below comment. I, now, have to compare a value , say AGE, in both C1 and A1, which inside B1. Now How do I do that ? If I try the functions or values , I will give me compiler error because the compiler is still oblivious of the class type of the object C1 and A1

Also I could have saved X1 instead of A1 in the first place. Now I might have to check for a different property check like ADDRESS. This changes the dimension of the problem drastically.

  • 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-17T19:51:59+00:00Added an answer on May 17, 2026 at 7:51 pm

    instanceof operator works only with staticly loaded classes. For dynamically loaded classes, use the isInstance method on the Class class.

    if (class11.isInstance(C1)) {
        // do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you guys and gals got any tips or hacks for making the most
I have heard several podcasters (most recently the guys on DotNetRocks ) say that
Problem solved: Thanks guys, see my answer below. I have a website running in
I have got a problem with my codeigniter library. To transform database data into
When reading about SQL Injection and XSS i was wondering if you guys have
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
Have you guys had any experiences (positive or negative) by placing your source code/solution
Ok guys just a small game: I have some specifications for a project. At
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
Hiya - been pointed at you guys by a friend of mine. I have

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.