Skip to content

Organize Imports should be smarter about single-letter types #1438

Closed

Description

@anthonyvdotbe

When there's an unresolved single-letter type usage in the code, doing Organize Imports should not blindly import a type it finds

Environment
  • Operating System: Windows 10
  • JDK version: 14
  • Visual Studio Code version: 1.45.0
  • Java extension version: 0.61.0
Steps To Reproduce
  1. do Organize Imports on the code below, while there's a single type T available for import (in my case it was inside Apache POI, but you could just create a trivial T.java file
import java.util.Map;

//import org.apache.poi.ss.formula.functions.T;

public class Bar {

    public void print(Comparable<T> bar, Map<Integer, T> whatever) {

    }

}
Current Result

the type T is imported

Expected Result

the actual issue here is that I forgot to specify the type variable T. Ideally, the extension would give a single error saying exactly that. If that's not feasible, it should at least ask confirmation before importing single-letter types, even if there's only a single one available: the chances that the user actually wants to import such a type are much smaller than the chance that there's an error w.r.t. type variables

Activity

  1. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    Parameterized types are not limited to single-letter symbols. For example you can have a class like this:

    public class MyClaz<TA> {
        public void print(Comparable<TA> bar, Map<Integer, TA> whatever) {
        }
    }
    

    Secondly, the current behavior matches that of eclipse. If you don't parameterize your class, any reasonable implementation would assume a class within your project or your classpath might be your parameter type.

    Closing, works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions