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

The Archive Base Latest Questions

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

I have a method that takes a list of SResource objects public static List<STriple>

  • 0

I have a method that takes a list of SResource objects

public static List<STriple> listTriples(List<SResource> subjects){
//... do stuff
}

Why can’t I do this

List<IndexResource> resultsAsList = new ArrayList<IndexResource>();
    resultsAsList.addAll(allResults.keySet()); // I could possible not use lists and just use sets and therefore get rid of this line, but that is a different issue
List<STriple> triples = new ArrayList<STriple>();
    triples = TriplesDao.listTriples(resultsAsList);

(The compiler tells me I have to make triples use SResource objects.)

When IndexResource is a subclass of SResource

public class IndexResource extends SResource{ 
// .... class code here
}

I would have thought this has to be possible, so maybe I am doing something else wrong. I can post more code if you suggest it.

  • 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-24T10:06:15+00:00Added an answer on May 24, 2026 at 10:06 am

    You can do it, using wildcards:

    public static List<STriple> listTriples(List<? extends SResource> subjects){
        //... do stuff
    }
    

    The new declaration uses a bounded wildcard, which says that the generic parameter will be either an SResource, or a type that extends it.

    In exchange for accepting the List<> this way, “do stuff” can’t include inserting into subjects. If you’re just reading from the subjects in the method, then this change should get you the results you want.

    EDIT: To see why wildcards are needed, consider this (illegal in Java) code:

    List<String> strings = new ArrayList<String>();
    List<Object> objList = string; // Not actually legal, even though string "is an" object
    objList.add(new Integer(3)); // Oh no! We've put an Integer into an ArrayList<String>!
    

    That’s obviously not typesafe. With wilcards, though, you can do this:

    List<String> strings = new ArrayList<String>();
    string.add("Hello");
    List<? extends Object> objList = strings; // Works!
    objList.add(new Integer(3)); // Compile-time error due to the wildcard restriction
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that takes a list of entities ( Class es) and
I have a Filter Method in my User Class, that takes in a list
I'm wondering how to go about testing this. I have a method that takes
I have a method that takes a List<int> , which is a list of
I have a python method that takes a list of tuples of the form
I have a search method that takes a list of ID's and I wish
If you have a method that needs to be tested that takes a list
I have the following extension method that takes a List and converts it to
I have a method that takes List<Foobar> and Foobar as parameters. Foobar is a
i have a simple method that takes a generic List parameter but for some

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.