This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c6390d398 Trivial refactor: GroovyObjectSupport.setMetaClass uses a 
ternary
0c6390d398 is described below

commit 0c6390d398691bc93a4f019ec08716ef5b878854
Author: Daniel Sun <[email protected]>
AuthorDate: Mon Sep 7 02:38:04 2026 +0900

    Trivial refactor: GroovyObjectSupport.setMetaClass uses a ternary
    
    Replace Optional.ofNullable(...).orElseGet(...) with a null check so the
    method does not allocate an Optional on every metaClass assignment.
---
 src/main/java/groovy/lang/GroovyObjectSupport.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/main/java/groovy/lang/GroovyObjectSupport.java 
b/src/main/java/groovy/lang/GroovyObjectSupport.java
index ef8c27d0ce..693459d491 100644
--- a/src/main/java/groovy/lang/GroovyObjectSupport.java
+++ b/src/main/java/groovy/lang/GroovyObjectSupport.java
@@ -21,7 +21,6 @@ package groovy.lang;
 import org.codehaus.groovy.runtime.InvokerHelper;
 
 import java.beans.Transient;
-import java.util.Optional;
 
 /**
  * Base class for Java objects wishing to be Groovy objects.
@@ -41,7 +40,7 @@ public abstract class GroovyObjectSupport implements 
GroovyObject {
     /** {@inheritDoc} */
     @Override
     public void setMetaClass(/*@Nullable*/ final MetaClass metaClass) {
-        this.metaClass = 
Optional.ofNullable(metaClass).orElseGet(this::getDefaultMetaClass);
+        this.metaClass = metaClass != null ? metaClass : getDefaultMetaClass();
     }
 
     private MetaClass getDefaultMetaClass() {

Reply via email to