diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-22 21:10:33 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-22 21:10:33 +0000 |
commit | 9853b5b8292650d8e192b500e636dc441550eef7 (patch) | |
tree | ec3a85b9b7af29c9fbd3bba17389791f083394cc /src/library-aux | |
parent | e49ec10e93eeec1af775096de07dd46a7d0a1fad (diff) | |
download | scala-9853b5b8292650d8e192b500e636dc441550eef7.tar.gz scala-9853b5b8292650d8e192b500e636dc441550eef7.tar.bz2 scala-9853b5b8292650d8e192b500e636dc441550eef7.zip |
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.)
Diffstat (limited to 'src/library-aux')
-rw-r--r-- | src/library-aux/scala/Any.scala | 6 |
1 files changed, 6 insertions, 0 deletions
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. |