-
Notifications
You must be signed in to change notification settings - Fork 21
Unexpected warning when comparing with java.lang.Object
#9953
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9953?orig=1 |
@SethTisue said: |
@som-snytt said: $ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.
scala> val e = new java.util.EventObject("hi")
e: java.util.EventObject = java.util.EventObject[source=hi]
scala> e.getSource
res0: Object = hi
scala> e.getSource == "hi"
res1: Boolean = true
scala> trait X extends Any
defined trait X
scala> val x = null.asInstanceOf[X]
x: X = null
scala> e.getSource == x
<console>:15: warning: Object and X are unrelated: they will most likely never compare equal
e.getSource == x
^
res2: Boolean = false
scala> val o = new Object
o: Object = java.lang.Object@6aaa5eb0
scala> o == x
<console>:15: warning: Object and X are unrelated: they will most likely never compare equal
o == x
^
res3: Boolean = false
scala> |
@Atry said: Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.
scala> trait X extends Any
defined trait X
scala> object O extends X
defined object O
scala> (O: Object) == (O: X)
<console>:14: warning: Object and X are unrelated: they will most likely never compare equal
(O: Object) == (O: X)
^
res0: Boolean = true |
@som-snytt said: |
@som-snytt said: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I compare a
java.lang.Object
with a Scala type, the Scala compiler report the following warning:The warning is incorrect. The comparison does return
true
for my case.The text was updated successfully, but these errors were encountered: