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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:15:08+00:00 2026-05-30T02:15:08+00:00

With solid C++ in my back some Java concepts are not 100% clear. List<SomeInterface>

  • 0

With solid C++ in my back some Java concepts are not 100% clear.

List<SomeInterface> list = new ArrayList<SomeImplementation>; 

This is 100% clear needs no explanation – but it has consequences…

interface Drivable {...}
class Car implements Drivable  {...}
class Bike implements Drivable  {...}
class Skateboard implements Drivable  {...}

class MyGarage{
List<Driveable> myRides;

public void addRides( List<Driveable> rideList ){...} 

Is not callable with List<Car>. However I can add Cars to myRides by:

public void addCars( List<Car> carList ){
myRides.addAll( new List<Driveable>( carList ) );

Q1: Is this a good idea?

I would really want something like the first function to work. By doing something that corresponds to C++ const& and adding a copy of the incoming carList to myRides I am thinking carList would be protected from illegal access. My hopes of adding final as a function argument were crushed.

Q2: Is there some way to make a fully callable addRides(List<Driveable> rideList) work?

Nor is overloading ( List<Car> List<Bike> etc ) legal.

And yes I can make this work by adding separate functions addBikes() addCars etc or I could do new List<Drivable> at each point of call. But I am hoping for something sleeker.

Q3: Any suggestions?

Thanks a lot!
Adam

  • 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-30T02:15:10+00:00Added an answer on May 30, 2026 at 2:15 am

    Your addRides method should be like this:

    public void addRides(Collection<? extends Drivable> c)
    

    When in doubt about generics usage, look for the collection interfaces in java.util, they have lots of examples, what you want to do is the same as what Collection.addAll() does.

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

Sidebar

Related Questions

BUMP: This is not a dead request. I'm still hoping to get a solid
CSS table tr {border-bottom:1px solid #008999} HTML <table width=100% cellspacing=0 cellpadding=0> <thead> <tr> <th
I'm having some trouble with a fluid layout (with images using max-width:100%) in Internet
Hello I use this code for toggle some css properties: $(document).ready(function() { $('li#last').toggle(function(){ $(this).css({border-bottom:
I previously asked a similar question on this topic a while back and got
I have a sales simulator written in C#. I did not write this however
New to document-oriented database concepts and have a few high-level questions related to orders
Back to the basics... For reference types, one can do this: SomeType someObject =
I just went through some MVC tutorials after checking this site out for a
How solid is Mono for C# development on Linux and OS X? I've been

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.