Java – expose implementation information to callers?

In JLS capture conversion, it discusses two methods of writing reverse method signatures:

> public static void reverse(List<?> list); > public static< T> void reverse(List< T> list);

My question is why the second one exposes the implementation information to the caller? Especially in the example, it indicates that the second is undesirable because it exposes implementation information to the caller

Solution

List and lt;? > When you iterate over LYST, you will return an element of type object (for example: LYST. Get (..))

List and lt; T> Elements of type T will be returned

This helps hide unwanted information to those who implement / use the interface

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>