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

Confusing error message about non-static method referenced from a static context

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      generic
    • OS:
      generic

      Description

      Consider the example below. The error message is not actually wrong, but
      a more helpful message would have suggested using Test.this.hashCode
      instead.

      $ cat -n Test.java 1 class Test {
           2 class Inner {
           3 public int hashCode() {
           4 return Test.hashCode(null);
           5 }
           6 }
           7 int hashCode(Object o) { return o.hashCode(); }
           8 }
      $ javac Test.java
      Test.java:4: non-static method hashCode(java.lang.Object) cannot be referenced from a static context
                  return Test.hashCode(null);
                             ^
      1 error
      ###@###.### 10/28/04 02:48 GMT

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ahe Peter Ahe
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: