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

Get compile-time error with gnerics method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • tools
    • x86
    • windows_xp


      ###@###.### 2004-04-22

      J2SE Version (please include all output from java -version flag):
        java version "1.5.0-beta2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b46)
        Java HotSpot(TM) Client VM (build 1.5.0-beta2-b46, mixed mode)

      Does this problem occur on J2SE 1.4 or 1.4.1 or 1.4.2? Yes / No (pick one)
        No

      Operating System Configuration Information (be specific):
        WinXP

      Hardware Configuration Information (be specific):
        Dell Optiplex

      Bug Description:
        Get compile-time error with getPropertyMethods().get(property) method

      Steps to Reproduce (be specific):
        This gives me a compile-time error:
         
          Method meth = di.getPropertyMethods().get(property);

          Compiling 1 source file to C:\devel\bjv2\data\ant-build\useCase
          C:\devel\bjv2\data\useCase\journals\TestUtils.java:76: incompatible types
             found : java.lang.Object
             required: java.lang.reflect.Method
                      Method meth = di.getPropertyMethods().get(property);

         The method getPropertyMethods() is declared as returning
         Map<String,Method>. If break the line down into two lines as follows,
         the error message goes away:

          Map<String,Method> pm = di.getPropertyMethods();
          Method meth = pm.get(property);


      Test program:
      -----------------

      import java.util.Map;
      import java.lang.reflect.Method;

      /**
      * @author Matthew Pocock
      */
      public class TestIndirectTemplates
      {
      interface Foo <FType>
      {
      public Map<String, Method> getMethods();
      }

      class Baz
      {
      {
      Foo foo = null;
      Method meth = foo.getMethods().get("prop");
      }
      }
      }

      It gives the following compile error:

      C:\devel\bjv2\data\src\org\bjv2\integrator\impl\TestIndirectTemplates.java:20:
      incompatible types
      found : java.lang.Object
      required: java.lang.reflect.Method
       Method meth = foo.getMethods().get("prop");
                                        ^

      If you declare Foo as "interface Foo" without the type parameter, then
      the code compiles. If you declare "Foo<Map> foo = null;" then the class
      compiles. The error is not affected by making Foo a class rather than an
      interface. If the get() line is changed to be just
      'foo.getMethods().get("prop");' then no error is raised under any of
      these circumstances.

            gafter Neal Gafter (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: