简体   繁体   中英

What are the benefits of bounded type parameters?

See below example,What are the benefits of bounded type parameters comparing f(U u) to g(I obj) ?

interface I {}
class A {
    public static <U extends I> void f(U u){ }
    public static void g(I obj) { }
}

There aren't any, for this particular case. You can execute exactly the same operations on U (knowing that U extends I ) as you can on an I .

More often you'll see cases for which it makes an actual difference:

public static <U extends I> void f(Collection<U> collection)

or, more generally, the bounded type parameter being used as a parameter for another generic type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM