tilgalas commented on code in PR #32081:
URL: https://github.com/apache/beam/pull/32081#discussion_r1816634987


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/FieldValueGetter.java:
##########
@@ -29,7 +30,7 @@
  * <p>Implementations of this interface are generated at runtime to map object 
fields to Row fields.
  */
 @Internal
-public interface FieldValueGetter<ObjectT, ValueT> extends Serializable {
+public interface FieldValueGetter<ObjectT extends @NonNull Object, ValueT> 
extends Serializable {

Review Comment:
   so apparently there's a difference (I don't understand why it would be so, 
though) between a `@NonNull T` and `T extends @NonNull Object` - here's an 
example, consider:
   ```
     public interface I<T extends @NonNull Object> {
         T getT();
     }
   ```
   with a signature as above, we can only write:
   ```
     public static <T extends @NonNull Object> void f(I<T> i) {
       System.out.println(i.getT().getClass());
     }
   ```
   or alternatively:
   ```
     public static <T> void f(I<@NonNull T> i) {
       System.out.println(i.getT().getClass());
     }
   ``` 
   The checkerframework will make sure that we propagate the non-nullness of 
the parameter. 
   This won't work for example:
   ```
     public static <@Nullable T> void f(I<T> i) {
       T t = i.getT();
       if (t != null) {
         System.out.println(t.getClass());
       }
     }
   ```
   nor will this:
   ```
     public static <T> void f(I<@Nullable T> i) {
       T t = i.getT();
       if (t != null) {
         System.out.println(t.getClass());
       }
     }
   ```
   but it will work if I change the signature of `I` to:
   ```
     public interface I<@NonNull T> {
         T getT();
     }
   ```
   in other words, the `@NonNull T` annotation on the interface is not really 
enforced anywhere, it's more like a suggestion, and so it's not really 
expressing the concept of the interface only works with `@NonNull` types 



-- 
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