Java cfObject,方法名称为CF保留字

E-M*_*add 2 java coldfusion braintree

我一直在ColdFusion中进行Braintree集成.Braintree不直接支持CF,但它们提供了一个Java库,到目前为止我所做的一切都非常好......直到现在.似乎某些对象(特别是搜索功能)具有无法从CF访问的方法,我怀疑它是因为它们是CF保留字,例如"是"和"包含".有没有办法解决这个问题?

<cfscript>
gate = createObject( "java", "com.braintreegateway.BraintreeGateway" ).init(env,merchant.getMerchantAccountId(), merchant.getMerchantAccountPublicSecret(),merchant.getMerchantAccountPrivateSecret());
req = createObject( "java","com.braintreegateway.CustomerSearchRequest").id().is("#user.getUserId()#");
customer = gate.customer().search(req);
</cfscript>
Run Code Online (Sandbox Code Playgroud)

引发的错误:无效的CFML构造...... ColdFusion正在查看以下文本:是

Ada*_*ron 6

这表示CF编译器中的错误.有一个在CF没有规定一个人不能定义一个名为任何方法is()this(),实际上在基本情况有一个与调用他们要么没有问题.此代码演示:

<!--- Junk.cfc --->
<cfcomponent>
    <cffunction name="is">
        <cfreturn true>
    </cffunction>
    <cffunction name="contains">
        <cfreturn true>
    </cffunction>
</cfcomponent>

<!--- test.cfm --->
<cfset o = new Junk()>

<cfoutput>
    #o.is()#<br />
    #o.contains()#<br />
</cfoutput>
Run Code Online (Sandbox Code Playgroud)

这 - 可预测 - 输出:

true
true
Run Code Online (Sandbox Code Playgroud)

但是,如果我们将一个init()方法引入Junk.cfc,我们就会遇到问题,因此:

<cffunction name="init">
    <cfreturn this>
</cffunction>
Run Code Online (Sandbox Code Playgroud)

然后相应地调整test.cfm:

#o.init().is()#<br />
#o.init().contains()#<br />
Run Code Online (Sandbox Code Playgroud)

这会导致编译器错误:

在第19行的第4行找到无效的CFML构造.

ColdFusion正在查看以下文字:

[...]

coldfusion.compiler.ParseException:在第19行的第4行找到无效的CFML构造.

at coldfusion.compiler.cfml40.generateParseException(cfml40.java:12135)
Run Code Online (Sandbox Code Playgroud)

[等等]

o.init().is()如果没有问题,没有正当理由不应该没问题o.is().

我建议你提交一个bug.我会投票支持它.

作为一种解决方法,如果使用中间值而不是方法链,则应该没问题.