Skip to content

Code completion for anonymous class construction doesn't use diamond operator in Java 9+ #9295

@nmatt

Description

@nmatt

Apache NetBeans version

Apache NetBeans 29

What happened

Since Java 9, the constructor calls for a parameterized anonymous class can use the diamond operator instead of repeating the type arguments. However, NetBeans code completion still inserts the type arguments.

Language / Project Type / NetBeans Component

Java

How to reproduce

Example:

abstract class Example<T>
{
    abstract T foo();
    
    static 
    {
        Example<ThreadLocal<StackTraceElement>> example = new Example
    }
}

Invoking code completion results in unnecessarily repeating the type argument:

        Example<ThreadLocal<StackTraceElement>> example = new Example<ThreadLocal<StackTraceElement>>() {
            ...
        };

Expected result for source level ≥ 9:

        Example<ThreadLocal<StackTraceElement>> example = new Example<>() {
            ...
        };

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows

JDK

21

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions