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

  • Home
  • SEARCH
  • 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 3243090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:23:30+00:00 2026-05-17T18:23:30+00:00

In Java generics you can use & to specify multiple interfaces as type bounds

  • 0

In Java generics you can use “&” to specify multiple interfaces as type bounds for a type parameter. This allows us for example to manipulate objects of different types with common interfaces to be manipulated uniformly even if there is not an parent interface for those common ones. My question is, how can this be used? For What purposes? I can imagine using this feature for collections, but how is it really than creating a new interface? This cannot be used dynamically, nor for type parameters. Is it just a syntactic sugar, or is there real use case for this feature?

  • 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-17T18:23:31+00:00Added an answer on May 17, 2026 at 6:23 pm

    Here is an example taken from my Java Generics book:

    public static <S extends Readable & Closeable, 
                  T extends Appendable & Closeable> 
           void copy(S source , T target, int size){
    
        //code to copy from source to target 
    
    }
    

    The method above takes any source that implements both Readable and Closeable and any target that implements both Appendable and Closeable and copies from source to target. You might wonder why we can’t simplify it to:

    public static void copy(Reader source, Writer target, int size)
    

    This will indeed admit most of the
    same classes but not all of them. For
    instance, PrintStream implements
    both Appendable and Closeable, but
    is not a subclass of Writer.
    Furthermore, you can’t rule out the
    possibility that some programmer using
    your code might have his or her own
    custom class that, say, implements
    Readable and Closeable but is not
    a subclass of Reader.

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

Sidebar

Related Questions

I'm experimenting with generics in Java, and thought of this example. If I have
OK - I know that Java generics can be a minefield for the unwary,
Can someone please explain to me difference between extends and super in java generics
With generics on languages like C# or Java, you can have a factory that
How can I print the type of a generic java type? Reflection? Any tricks?
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
Can I override and use a subclass for the template type in as the
Possible Duplicate: Java Generics Hi, Can anyone please explain the difference of the three
In java a class can implement Iterable which lets you use the foreach() statement
How can I make this java generic cast ? public interface IField { }

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.