Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

"===" equivalent in Java

While comparing two values in Java, how do you test if both, the type and the value, are equivalent?

I know in JavaScript === can be used to accomplish this, so I tried that in Java, but it didn’t work.

I know this is a simple question, but I tried looking it up and I couldn’t find out what it was.

Answer*

Draft saved
Draft discarded
Cancel
13
  • What about in Java 10 where you can now use var? Commented Jun 20, 2019 at 12:04
  • 1
    @lealceldeiro JavaScript doesn't have doubles or integers. Just "Numbers" which are essentially doubles. So 10 and 10.0 are both the same. Commented Jun 20, 2019 at 12:26
  • 1
    @JavaCakes They write the same thing for me (1, 2). Commented Jun 20, 2019 at 17:40
  • 2
    @Nexevis var in Java 10 is pure syntactic sugar to avoid writing the declaration type of the variable when it can be inferred from the created instance. The language is still strongly-typed. Commented Jun 24, 2019 at 19:30
  • 1
    TL;DR: === in Java is .equals() Commented Apr 17, 2023 at 8:07

lang-java

AltStyle によって変換されたページ (->オリジナル) /