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

Any and AnyVal should provide getClass method #864

Closed
scabug opened this issue May 8, 2008 · 8 comments
Closed

Any and AnyVal should provide getClass method #864

scabug opened this issue May 8, 2008 · 8 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 8, 2008

Given that

scala> classOf[Int]
res6: java.lang.Class[Int] = int

It should be the case that the following works

scala> 1.getClass
<console>:5: error: type mismatch;
 found   : Int
 required: ?{val getClass: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method int2Integer in object Predef of type (Int)java.lang.Integer
 and method intWrapper in object Predef of type (Int)scala.runtime.RichInt
 are possible conversion functions from Int to ?{val getClass: ?}
       1.getClass
       ^
@scabug
Copy link
Author

scabug commented May 8, 2008

Imported From: https://issues.scala-lang.org/browse/SI-864?orig=1
Reporter: Geoffrey Alan Washburn (washburn)

@scabug
Copy link
Author

scabug commented May 8, 2008

@dubochet said:
The proper fix for this issue is that described in #496. I will therefore mark it as a duplicate.

@scabug
Copy link
Author

scabug commented May 8, 2008

Geoffrey Alan Washburn (washburn) said:
I am not sure I see how fixing #496 is supposed to resolve this unless you want the default implicit conversion to be to RichFoo. Is that the plan?

@scabug
Copy link
Author

scabug commented May 8, 2008

Geoffrey Alan Washburn (washburn) said:
Furthermore, I think it would still be better to fix this problem. Even if the issue with implicit conversions is resolved, ideally the Proxy trait should provide a getClass method that forwards to its "self" member. However, there is presently no way to define such a method because we cannot use the getClass method on it, because it is not a subtype of AnyRef, and even if Proxy were parametrized rather than giving its "self" member type Any, classOf[T] does not work for type parameters.

@scabug
Copy link
Author

scabug commented May 14, 2008

@dubochet said:
Since getClass mostly makes sense within the scope of (Java) reflection and since reflection uses the boxed versions of values (Integer for int, etc) it may be logical to have 1.getClass return classOf[Integer].

In that sense fixing #496 may still fix that issue.

I agree this would be a situation where Scala's object model would loose some of its purity by exposing the messy boxing business. On the other hand, when doing reflection, one has to deal with it.

Let's decide once we have a better idea on how Scala's own reflection system will look.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug
Copy link
Author

scabug commented Mar 15, 2009

@odersky said:
I disagree with Gilles. 1.getClass should either return Integer.TYPE, or it should not work at all (as it currently does). Returning Integer.class is misleading. Given this requirement, I fear there's not much we can do, as a boxed int is an Integer, and there's nothing we can do to distinguish the two.

@scabug
Copy link
Author

scabug commented Jul 24, 2011

@SethTisue said:
this was fixed by Paul in r25173. see also #496

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

No branches or pull requests

2 participants