On Oct 13, 2013, at 4:33 PM, Tal Liron <[email protected]> wrote:

> ConsString can cause some hard-to-find bugs when interacting with Java 
> classes.
> 
> [...]
> 
> 1. Document it in the user guide, possibly with the simple example I gave 
> above. I expect that many of these bugs will happen when dealing with generic 
> classes, such as those in java.util. The workaround for the example above:
> 
>  var key = String(prefix + 'b')
> 
> But that's hardly intuitively necessary.

It is documented in 
<http://download.java.net/jdk8/docs/technotes/guides/scripting/prog_guide/javascript.html#A1147390>

> 
> 2. It may be a good idea for Nashorn to always coerce ConsString into String 
> when interacting with Java, even if the method signature expects an Object.

It's not really easy to do consistently, for subtle reasons having to do with 
not imposing conversions on method invocation parameters to which a JLS method 
invocation conversion applies; trivially, anything-to-Object always applies. 
Introducing an argument filter on every parameter of declared type Object is 
prohibitive with regard to performance.

Attila.

> The one downside I can think of is that it will make it impossible to offer 
> special handling for ConsString in Java classes. This would seem, however, to 
> be quite a rare usage and may not be worth the potential for awful bugs.
> 
> What do you think?
> 
> 

Reply via email to