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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:46:18+00:00 2026-05-25T23:46:18+00:00

Say I have the following java code: Object myObj = new ArrayList(); List myList

  • 0

Say I have the following java code:

Object myObj = new ArrayList();
List myList = new ArrayList();

I would like to know how to determine which class or interface a given object is typed with.

Note that I am not talking of the type the object was instanciated from (here ArrayList) but rather the type on the left-hand side of the expression so that would be in the example above Object for myObj and List for myList.

How do I call this “left-hand side” type in proper parlance?

Also, how do I call the “right-hand side” type?

How do I determine programmatically what is this “left-hand side” type?

Regards,

  • 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-25T23:46:19+00:00Added an answer on May 25, 2026 at 11:46 pm

    The type used on the left-hand side is not the type of an object. It’s the type of a variable. (The static or compile-time type.)

    It’s worth differentiating between a variable and an object – a variable has a name, a type and a storage location. The storage location contains value compatible with the type of the variable.

    Now to find the type of a variable at execution time, you’d need some sort of reference to the variable itself as a variable. For example, if it’s a field (static or instance) you can fetch the appropriate Field reference, you can ask for the type using Field.getType().

    If it’s a local variable you’ll find it a bit harder. If you can explain what you’re trying to achieve (rather than the mechanism you think will help you achieve it) we may be able to help more.

    Calling myList.getClass() or anything like that will not do what you want, because that will deal with the value of myList, not the variable itself.

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

Sidebar

Related Questions

Say I have the following piece of java code ArrayList<Double> myList = new Double[100];
Say suppose I have the following Java code. public class Example { public static
Let's say I have the following ruby code : def use_object(object) puts object.some_method end
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
Lets say i have the following bit of code import java.sql.Connection; import java.sql.DriverManager; import
Say I have the following simple java bean: class MyBean { private Date startDate;
Say we have the following method: private MyObject foo = new MyObject(); // and
Say I have the following C++: char *p = new char[cb]; SOME_STRUCT *pSS =
I have the following code: Hashtable env1 = new Hashtable(); env1.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,com.ibm.websphere.naming.WsnInitialContextFactory); log.info(Executed step 1);
I have this code in Java: InputStreamReader isr = new InputStreamReader(getInputStream()); BufferedReader ir =

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.