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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:50:58+00:00 2026-05-25T14:50:58+00:00

I find the following code remarkable in Java: ArrayList<String> l1 = new ArrayList<String>(); ArrayList<Integer>

  • 0

I find the following code remarkable in Java:

    ArrayList<String> l1 = new ArrayList<String>();
    ArrayList<Integer> l2 = new ArrayList<Integer>();
    System.out.println(l1.getClass() == l2.getClass()); // true
    System.out.println(l2.getClass().isAssignableFrom(l1.getClass())); // true too
    //ArrayList<Integer> l3 = l1; // won't compile though

I don’t quite understand the details of “isAssignableFrom”. Of course, I want the compiler to stop l3 = l2, but it seems to be in contradiction to the previous line? (I’m sure there are subtle points here, that’s what I’m after 🙂

  • 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-25T14:50:58+00:00Added an answer on May 25, 2026 at 2:50 pm

    All of the <Blah> information is stripped away after compile time. As far as the bytecode is concerned, they’re all the same class.

    When it comes to during the compile, they’re checked for consistency and compatibility.

    So when it does the check of l2.getClass().isAssignableFrom(l1.getClass()) it’s saying is ArrayList assignable from ArrayList? and the answer is yes. But because during the compile it still has type information, it’s not allowed.

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

Sidebar

Related Questions

The following code: var constant = Expression.Constant(find me, typeof(string)); // memberExpression evaluates to a
I have been trying to find out why the following lines of code do
I understand that the following code can (perhaps not very efficiently) find out a
I have the following code to find out free disk space on a UNC
I'm using the following code to find out which part of the page the
consider the following code: if (matcher1.find()) { String str = line.substring(matcher1.start()+7,matcher1.end()-1); /*+7 and -1
I tried the following code to find out maximum segment size in TCP and
In Java, I find the following code much cleaner and easier to maintain than
Do you find the following C# code legible? private bool CanExecuteAdd(string parameter) { return
I had used the following code to find the length String str=strLenData.toString(); int ipLen=

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.