Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 52F72200B84 for ; Mon, 29 Aug 2016 00:07:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 519B6160AC7; Sun, 28 Aug 2016 22:07:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 968CD160AB4 for ; Mon, 29 Aug 2016 00:07:21 +0200 (CEST) Received: (qmail 58241 invoked by uid 500); 28 Aug 2016 22:07:20 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 58226 invoked by uid 99); 28 Aug 2016 22:07:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Aug 2016 22:07:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id A046B2C0150 for ; Sun, 28 Aug 2016 22:07:20 +0000 (UTC) Date: Sun, 28 Aug 2016 22:07:20 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-7611) java.util.Optional should evaluate to false if empty MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 28 Aug 2016 22:07:22 -0000 [ https://issues.apache.org/jira/browse/GROOVY-7611?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15444198#comment-15444198 ] ASF GitHub Bot commented on GROOVY-7611: ---------------------------------------- Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/403#discussion_r76540119 --- Diff: src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java --- @@ -10563,13 +10563,21 @@ private void prepare() { /** * Coerce an object instance to a boolean value. * An object is coerced to true if it's not null, to false if it is null. + * One exception to this is in the case of a non-null {@code java.util.Optional} + * in which case the result of the {@code isPresent} method is returned. * * @param object the object to coerce * @return the boolean value * @since 1.7.0 */ public static boolean asBoolean(Object object) { - return object != null; + if (object == null) { + return false; + } + if ("java.util.Optional".equals(object.getClass().getName())) { --- End diff -- Good suggestion, I've added the todo comment. > java.util.Optional should evaluate to false if empty > ---------------------------------------------------- > > Key: GROOVY-7611 > URL: https://issues.apache.org/jira/browse/GROOVY-7611 > Project: Groovy > Issue Type: Improvement > Affects Versions: 2.4.5 > Reporter: Christopher Smith > Priority: Minor > > In the spirit of the rest of the Groovy truth semantics, I suggest that an empty {{java.util.Optional}}, which is essentially a stream-safe equivalent of {{null}}, should evaluate to false: {{asBoolean()}} should simply delegate to {{isPresent()}}. -- This message was sent by Atlassian JIRA (v6.3.4#6332)