cancel
Showing results for 
Search instead for 
Did you mean: 

Ambiguous call to String.replace() on java.lang.Strings

jevon
Champ in-the-making
Champ in-the-making
I was trying to use the following code:

var s = escape(args["a"]);

function escape(s) {
  return s.replace(/[\\]/g, "\\\\").replace(/[\"]/g, "\\\"");
}

This is a fairly simple usecase, but I was getting the following error:

The choice of Java constructor replace matching JavaScript argument types (function,string) is ambiguous; candidate constructors are: class java.lang.String replace(char,char); class java.lang.String replace(java.lang.CharSequence,java.lang.CharSequence)

This didn't make any sense to me, until I realised that it looks like Alfresco Javascript has TWO Strings: java.lang.Strings and "Javascript" strings.

A workaround is to "cast" it to a "Javascript" string as follows:

function escape(s) {
  return (s + "").replace(/[\\]/g, "\\\\").replace(/[\"]/g, "\\\"");
}

Is this intended behaviour?
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
this is Alfresco java script,by default it will treat string object as java string object.
most of the times things will be more similar to java then javascript in alfresco javascript.

joviermark
Champ in-the-making
Champ in-the-making
try this one….<a href="http://www.corelangs.com/js/string/replace.html">Javascript Replace</a>

Mark

Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.