ppkarwasz commented on code in PR #799:
URL: https://github.com/apache/commons-io/pull/799#discussion_r2429458884


##########
src/main/java/org/apache/commons/io/channels/CloseShieldChannel.java:
##########
@@ -53,11 +57,10 @@ private static Set<Class<?>> collectChannelInterfaces(final 
Class<?> type, final
      * Wraps a channel to shield it from being closed.
      *
      * @param channel The underlying channel to shield, not {@code null}.
-     * @param <T>     Any Channel type (interface or class).
      * @return A proxy that shields {@code close()} and enforces closed 
semantics on other calls.
      */
     @SuppressWarnings({ "unchecked", "resource" }) // caller closes
-    public static <T extends Channel> T wrap(final T channel) {
+    public static Channel wrap(final Channel channel) {

Review Comment:
   Leaving the generic will make the method easy to misuse. This will generate 
problems similar to those described in 
[TypeParameterUnusedInFormals](https://errorprone.info/bugpattern/TypeParameterUnusedInFormals),
 when hidden cast exceptions will occur if `T` resolves to a type that is not 
an interface.
   
   To preserve the safety of the API, maybe we should add overloads for the 
most important `Channel` subinterfaces (`ReadableByteChannel`, 
`WritableByteChannel` and `SeekableByteChannel`)? What do you think? Overload 
resolution will take care of selecting the right one.
   
   For less common interfaces, users can always make explicit casts after 
reading the Javadoc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to