Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8332325

Unhelpful 'cannot find symbol' error when a symbol exists of the wrong kind

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • tools
    • None

      In the following diagnostic, the symbol List.of exists (it's a method), but it's used in a context where a class is required (after `new`).

      The compiler just reports 'cannot find symbol' as the initial diagnostic. The details show that it's searching for a class named 'of' (in 'symbol: class of').

      It would perhaps be more clear for the diagnostic to mention that a symbol List.of exists, but that a class is required in this context.

      class T {
        List<?> xs = new List.of();
      }

      javac T.java
      cT.java:3: error: cannot find symbol
        List<?> xs = new List.of();
                             ^
        symbol: class of
        location: interface List
      1 error

            Unassigned Unassigned
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: