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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:44:06+00:00 2026-05-29T10:44:06+00:00

I got a list of Objects of class-type B (B inherits from A). How

  • 0

I got a list of Objects of class-type B (B inherits from A).
How can I downcast all the B-objects to A-objects without using a function to pull the needed information and create a new instance?

(defclass A () ( (varI :initarg :varI :accessor varI) ) )

(defclass B (A) ( (varII :initarg :varII :accessor varII) ) )

(defun generate-list-of-type-B-objects () (....does...some..stuff....))

(defvar *listoftypeA* (generate-list-of-type-B-objects) )

(I know this example is easy to rewrite, as I could make the method generate a list of type A objects, but the function is used somewhere else where type-B objects are needed, and I do not want to duplicate code)

  • 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-29T10:44:08+00:00Added an answer on May 29, 2026 at 10:44 am

    If you absolutely must convert your instances of class B into instances of class A, you can do a one-way conversion of them with the use of CHANGE-CLASS. This is a non-reversible change of each instance.

    Since I am not 100% sure what you actually want, the best suggestion I can give is “have you tried leaving them as class B and see if it works?”

    Chances are that it will just work, unless you have methods of a generic function somewhere that treat instances of class B differently than instances of class A. If it’s only about dropping the space that the extra slot would take, have you measured that it’s actually worth it (it probably isn’t, unless you have several thousands of instances of class B, where you could get by with instances of class A).

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

Sidebar

Related Questions

I've got a list of objects of type A . Each object has a
I've got a list of System.Drawing.RectangleF objects that all overlap the same RectangleF object.
I've got an object of type A which consists of a list of objects
I've got this function public static AdoEntity.Inspector GetInspectorWithInclude(int id, List<string> properties) { using (var
I've got a list of UserControl objects; when a menu option is clicked to
In the project I'm working on I have got a list List<Item> with objects
I got two collections of objects. For example: List<Foo> firstFoos = new List<Foo>(); List<Foo>
I've got a list of DIVS (products on a storepage) width the class chairdiv.
With reflection, you can look up a class from a string at run time,
I need to return a list of objects from a restful webservice. each object

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.