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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:59:14+00:00 2026-06-02T16:59:14+00:00

For example: I have two type of objects: public class Image { … }

  • 0

For example:

I have two type of objects:

public class Image {
...
}

And

public class Video {
...
}

I want to have a class that will contain a single list of those two objects, like this:

public class Media {

private List<Object> mediaList = new....
....
}
  • 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-06-02T16:59:16+00:00Added an answer on June 2, 2026 at 4:59 pm

    Create a parent class, and have Image and Video be children of it.

    You can then make the list of the parent type.

    import java.util.ArrayList;
    import java.util.List;
    
    public class Example
    {
        public abstract ImageVideo
        {
    
        }
    
        public class Image extends ImageVideo
        {
    
        }
    
        public class Video extends ImageVideo
        {
    
        }
    
        public static class Media
        {
            public static void main( String args[] )
            {
                Image image = new Example().new Image();
                Video video = new Example().new Video();
    
                List<ImageVideo> mediaList = new ArrayList<ImageVideo>();
    
                mediaList.add( image );
                mediaList.add( video );
            }
        }
    }
    

    Also, the following compiles, you would just have to cast the objects back when you retrieve them from the list.

    import java.util.ArrayList;
    import java.util.List;
    
    public class Example
    {
        public class Image
        {
    
        }
    
        public class Video
        {
    
        }
    
        public static class Media
        {
            public static void main( String args[] )
            {
                Image image = new Example().new Image();
                Video video = new Example().new Video();
    
                List<Object> mediaList = new ArrayList<Object>();
    
                mediaList.add( image );
                mediaList.add( video );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have a vector-like class that contains an array of objects of type T
I have two classes in a PHP application, B extending A for example. Class
I have the following two classes: public class User { public Integer userId; //
I have an extremely simple IMultiValueConverter that simply OR's two values. In the example
I have an ObservableCollection<Object> that contains two different types. I want to bind this
I have two objects of the same type and need to copy property values
Lets say you have various objects of arbitrary type that you would like to
I have a class that I have to call one or two methods a
So I have two custom complex types like this (oversimplified for this example): public

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.