From 9853b5b8292650d8e192b500e636dc441550eef7 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 22 Jun 2011 21:10:33 +0000 Subject: A total rewrite of "runtimeClass", discarding t... A total rewrite of "runtimeClass", discarding the user-space approach in favor of simply fixing getClass. def f1 = 5.getClass // Class[Int] def f2 = (5: AnyVal).getClass // Class[_ <: AnyVal] def f3 = (5: java.lang.Integer).getClass // Class[_ <: java.lang.Integer] class A class B extends A def f1 = (new B: Any).getClass().newInstance() // Any def f2 = (new B: AnyRef).getClass().newInstance() // AnyRef def f3 = (new B: A).getClass().newInstance() // A def f4 = (new B: B).getClass().newInstance() // B But that's not all! def f0[T >: B] = (new B: T).getClass().newInstance() def f5 = f0[Any] // Any def f6 = f0[AnyRef] // AnyRef def f7 = f0[A] // A def f8 = f0[B] // B Closes #490, #896, #4696. Review by moors. (Note: I think this is pretty good, but picky review requested.) --- src/library-aux/scala/Any.scala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/library-aux/scala/Any.scala') diff --git a/src/library-aux/scala/Any.scala b/src/library-aux/scala/Any.scala index 2feab8f836..490c546bbf 100644 --- a/src/library-aux/scala/Any.scala +++ b/src/library-aux/scala/Any.scala @@ -54,6 +54,12 @@ abstract class Any { */ def toString: String + /** Returns the runtime class representation of the object. + * + * @return a class object corresponding to the static type of the receiver + */ + def getClass(): Class[_] + /** Test two objects for equality. * * @param that the object to compare against this object for equality. -- cgit v1.2.3