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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:07:23+00:00 2026-05-25T01:07:23+00:00

I had two classes: ParentClass and SubClass. SubClass inherit from ParentClass. I had the

  • 0

I had two classes: ParentClass and SubClass. SubClass inherit from ParentClass.
I had the following code: (inside class)

List<SubClass> lstSub;

//some initialization

public ListIterator getLstIterator(int i) {
   return lstSub.listIterator(i);
}

And client class uses it the following way:

ListIterator<ParentClass> lstParent = getLstIterator(0); //assign ListIterators

So, the question:
What does the program do while assigning ListIterators:

1) it creates a new list and copies there elements from source list, casting them to ParentClass;

2) it simply creates a link to lstSub and from this time this list is interpreted as List for ListIterator?

Or it does something else?
I’m interested in it because of program performance. I’m new to Java and appreciate any help.

  • 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-25T01:07:24+00:00Added an answer on May 25, 2026 at 1:07 am

    It doesn’t create another list. If you get a list iterator without knowing the class in the list, that’s going to be an error in your generics usage. You should get a warning when you do that assignment, but it’s just a warning. When you actually use it it’ll cast to whatever class. Properly you’d hold on to that as ListIterator<? extends ParentClass> if you wanted a list iterator, but actually holding on to an iterator is a little weird.

    Finally, just a bit of advice, I’d not worry about performance of the language features too much, especially if you’re just getting your feet in the language.

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

Sidebar

Related Questions

If I had two sets of classes, like so <div class = link 1></div>
I've factored out common attributes from two classes into an abstract base class, however
I am concreting a question I had earlier. I have two classes in C++
If I had two classes in separate namespaces (and therefor files), and they both
I have two classes. And I want the code in the for loop in
I have a class that needs access to two other classes. Signin needs access
Say you had two classes A and B. If the relationship between is has-a
So I need to used two classes for my GUI, one class is called
I'm a programming student, and I've now had two classes in C#, this semester
I've recently had to break a simple class down into two versions, a Legacy

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.