Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: wildcard extends problem

  1. #1
    Junior Member
    Join Date
    Oct 2025
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb wildcard extends problem

    Question to supermammoth, why it not works?:
    "static void processPair(B b1, B b2, BiConsumer<? extends B, ? extends B> consumer) {
    consumer.accept(b1, b2);
    }"
    but it works?:
    "List<? extends B> lb = new ArrayList<B>();
    List<? super B> lc = new ArrayList<B>();"
    I dont understand wildcard logic in class and methods? Why B is extends of B in one place, but not another? Why it wroks normally for super in both cases?

    In common case,
    is B extends B?
    is B super B?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,183
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: wildcard extends problem

    Try asking this question on this forum: http://www.coderanch.com/forums

    Now posted here: https://coderanch.com/t/805376/java/wildcard-extends
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2025
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: wildcard extends problem

    Helpful answer from another forum. "Because you could call it: processPair(B, B, BiConsumer<C, C>); And B cannot be passed to BiConsumer<C, C>."
    Task done.

Similar Threads

  1. Problem with wildcard observers
    By Cornix in forum Collections and Generics
    Replies: 0
    Last Post: September 20th, 2014, 04:46 AM
  2. Generics Wildcard array of references?
    By vikassarin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 27th, 2014, 03:58 AM
  3. [SOLVED] wildcard delete
    By macko in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 1st, 2011, 03:31 PM
  4. Interface and Extends problem
    By DannyGT in forum Object Oriented Programming
    Replies: 1
    Last Post: September 1st, 2011, 01:01 PM
  5. [SOLVED] Extends JPanel painting problem
    By Philip in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 28th, 2010, 03:16 PM

Tags for this Thread