Scala Programming Language
  1. Scala Programming Language
  2. SI-4780

replace obj.asInstanceOf[AnyRef].getClass with obj.getClass

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      all

      Description

      One no longer needs to cast a primitive to an AnyRef before
      calling getClass. So,
      obj.asInstanceOf[AnyRef].getClass
      should be replaced with
      obj.getClass
      in the source tree.

      Running the following script:

      find . -name '*.scala' -type f -exec grep --with-filename 'asInstanceOf[AnyRef].getClass' {} \;
      shows the following files can be fixed:

      ./compiler/scala/reflect/internal/Types.scala: Console.println(indent + tp1 + " " + op + " " + arg2 + "?" /* + "("tp1.getClass","arg2.asInstanceOf[AnyRef].getClass")"*/)
      ./compiler/scala/tools/nsc/util/ScalaClassLoader.scala: def origin(x: Any): Option[URL] = originOfClass(x.asInstanceOf[AnyRef].getClass)
      ./compiler/scala/tools/nsc/interpreter/TypeStrings.scala: def anyClass(x: Any): JClass = if (x == null) null else x.asInstanceOf[AnyRef].getClass
      ./compiler/scala/tools/nsc/io/Pickler.scala: "no pickler found for "x" of class "+x.asInstanceOf[AnyRef].getClass.getName)
      ./library/scala/runtime/ScalaRunTime.scala: x != null && isArrayClass(x.asInstanceOf[AnyRef].getClass, atLevel)
      ./library/scala/collection/TraversableLike.scala: var string = repr.asInstanceOf[AnyRef].getClass.getName
      ./library/scala/MatchError.scala: else obj.toString() + " (of class " + obj.asInstanceOf[AnyRef].getClass.getName + ")"

        Activity

        Hide
        Commit Message Bot added a comment -

        (extempore in r25575) Replaced various now-unnecessary casts with straight getClass
        calls. Closes SI-4780, no review.

        Show
        Commit Message Bot added a comment - (extempore in r25575 ) Replaced various now-unnecessary casts with straight getClass calls. Closes SI-4780 , no review.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Richard Emberson
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development