You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/07/12 04:26:04 UTC

[GitHub] [netbeans] junichi11 commented on a change in pull request #2250: Minor improvements for php.api.phpmodule

junichi11 commented on a change in pull request #2250:
URL: https://github.com/apache/netbeans/pull/2250#discussion_r453265442



##########
File path: php/php.api.phpmodule/src/org/netbeans/modules/php/api/validation/ValidationResult.java
##########
@@ -80,6 +81,20 @@ public boolean hasErrors() {
         return new ArrayList<>(errors);
     }
 
+    /**
+     * Get the first error.
+     *
+     * @return the first error.
+     * @since 2.72
+     */
+    @CheckForNull
+    public Message getFirstError() {
+        if (hasErrors()) {
+            return errors.get(0);
+        }
+        return null;
+    }

Review comment:
       I also thought other implementations:
   
   #### Create Message.EMPTY and return it 
   ```java
       public Message getFirstError() {
           if (hasErrors()) {
               return errors.get(0);
           }
           return Message.EMPTY;
       }
   
       public static final class Message {
           public static final Message EMPTY = new Message("", ""); 
   
   ```
   #### Use Optional
   ```java
       public Optional<Message> getFirstError() {
           if (hasErrors()) {
               return Optional.of(errors.get(0));
           }
           return Optional.empty();
       }
   ```
   Which is better?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists