You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/04/29 17:24:52 UTC
[groovy] 01/01: Tweak plus operation for `Object` instance to align with Java
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/tweak-plus
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 6062b8f29c345161bfbb8f70eeb3bb7a98dd51a9
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 30 01:23:58 2022 +0800
Tweak plus operation for `Object` instance to align with Java
---
.../groovy/runtime/DefaultGroovyMethods.java | 33 ++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index baa6e62639..8c6c8b4061 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -24,6 +24,7 @@ import groovy.lang.DelegatesTo;
import groovy.lang.DelegatingMetaClass;
import groovy.lang.EmptyRange;
import groovy.lang.ExpandoMetaClass;
+import groovy.lang.GString;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.GroovySystem;
@@ -15668,6 +15669,38 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
return plus(Integer.valueOf(left), right);
}
+ /**
+ * Concatenate an object literal with a string
+ *
+ * <pre class="groovyTestCase">
+ * assert '[a:1] is a map' == [a:1] + ' is a map'
+ * </pre>
+ *
+ * @param left a Object
+ * @param right a String
+ * @return the concatenated string
+ * @since 4.0.2
+ */
+ public static String plus(Object left, String right) {
+ return toString(left) + right;
+ }
+
+ /**
+ * Concatenate an object literal with a gstring
+ *
+ * <pre class="groovyTestCase">
+ * assert '[a:1] is a map' == [a:1] + " is ${'a'} map"
+ * </pre>
+ *
+ * @param left a Object
+ * @param right a GString
+ * @return the concatenated string
+ * @since 4.0.2
+ */
+ public static String plus(Object left, GString right) {
+ return toString(left) + right;
+ }
+
/**
* Compare a Character and a Number. The ordinal value of the Character
* is used in the comparison (the ordinal value is the unicode