Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Jul 5, 2011 · 2 comments
Closed

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

scabug opened this issue Jul 5, 2011 · 2 comments
Assignees
Labels

Comments

@scabug
Copy link

@scabug scabug commented Jul 5, 2011

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 + ")"

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 5, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4780?orig=1
Reporter: Richard Emberson (rmemberson)

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 27, 2011

Commit Message Bot (anonymous) said:
(extempore in r25575) Replaced various now-unnecessary casts with straight getClass
calls. Closes #4780, no review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.