[
https://issues.apache.org/jira/browse/GROOVY-12319?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109508#comment-18109508
]
ASF GitHub Bot commented on GROOVY-12319:
-----------------------------------------
sonarqubecloud[bot] commented on PR #2845:
URL: https://github.com/apache/groovy/pull/2845#issuecomment-5463937177
## [](https://sonarcloud.io/dashboard?id=apache_groovy&pullRequest=2845)
**Quality Gate passed**
Issues
 [15 New
issues](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2845&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted
issues](https://sonarcloud.io/project/issues?id=apache_groovy&pullRequest=2845&issueStatuses=ACCEPTED)
Measures
 [0 Security
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_groovy&pullRequest=2845&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [81.4% Coverage on New
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2845&metric=new_coverage&view=list)
 [0.0% Duplication on New
Code](https://sonarcloud.io/component_measures?id=apache_groovy&pullRequest=2845&metric=new_duplicated_lines_density&view=list)
<!
> Java compatibility: remaining generic type syntax
> -------------------------------------------------
>
> Key: GROOVY-12319
> URL: https://issues.apache.org/jira/browse/GROOVY-12319
> Project: Groovy
> Issue Type: Improvement
> Reporter: Daniel Sun
> Priority: Major
>
> Groovy already accepts most Java generics. Three Java forms still fail — two
> in the parser, one in {{GenericsVisitor}}. Each has a local workaround.
> Method type arguments such as {{Helper.<String>identity(x\)}} already work
> and are not part of this request.
> h3. 1. Diamond {{<>}} on an anonymous class
> Java 9+ (JEP 213) allows:
> {code:java}
> Processor<String> p = new Processor<>() {
> public String process(String val) { return val; }
> };
> {code}
> Groovy rejects this with {{Cannot use diamond <> with anonymous inner
> classes}}. Writing new Processor<String>() \{ ... \} compiles.
> GROOVY-6730 and GROOVY-7159 were false-positive STC errors when diamond was
> _not_ used; they did not add this form.
> h3. 2. Qualified parameterized inner types ("rare" types)
> Java allows an inner type to keep the outer's type arguments:
> {code:java}
> class Outer<T> {
> class Inner<U> {}
> }
> Outer<String>.Inner<Integer> x;
> {code}
> Groovy fails to parse {{Outer<String>.Inner}} ({{Unexpected input}}). A
> factory that returns {{Inner}} without naming {{Outer<T>.Inner}} is a
> workaround. The same qualification appears in {{o.new Inner<Integer>(42)}}.
> h3. 3. Explicit type arguments on constructors, {{this()}} and {{super()}}
> Java allows:
> {code:java}
> class Box {
> <T> Box(T t) {}
> }
> new <String>Box("x");
> {code}
> and, on generic constructors, {{<T>this()}}, {{<T>super()}},
> {{recv.<T>super()}}, and {{outer.new <T>Inner(...)}}.
> Groovy fails at {{new <}} with {{Unexpected input: '<'}}. Inference ({{new
> Box("x")}}) is the workaround.
> Constructor type arguments are already tracked by GROOVY-10501. The
> {{this()}} / {{super()}} / inner-{{new}} forms are the same JLS production
> (JLS 15.9) and should be handled together.
> h3. Related
> * GROOVY-10501 — constructor type arguments (open)
> * GROOVY-6730, GROOVY-7159 — diamond + anonymous class, STC false positives
> (fixed)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)