Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.5.1
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
assert 'abc'.contains('a') //1
assert 'a' in ('abc'as List) //2
assert 'a' in 'abc' //3 this breaks
You ask a string if a substring is contained in it (//1). You can do that with the in-Keyword with Lists (//2), too. But you can't do this with the in-Keyword with Strings. It would be a consistent behaviour from Groovy if you could do //3.
The first of the above examples is actually mirroring contains in Java 5 ,e.g. 'abcd'.contains('bc') so there is no magic conversion to an array or list happening for the first operand. The 3rd example would be doing such magic. While an interesting suggestion, I don't think it is pulling its weight as a new feature. Adding as List or toList() to the example is all that is required and if we were going to make it automatic, it isn't obvious to me if it should behave like the 1st or 2nd examples.
Recommend we close this as Won't Fix.