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

Return to Answer

Bounty Awarded with 500 reputation awarded by Madara's Ghost
added 34 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y); // false

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types using the == operator and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y); // false

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types using the == operator and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

Add useful info about how to override equals and hashCode methods.
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

Add info
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice thatthe Object.equals method cannot be called on primitive types.

Some useful readings are:

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice that Object.equals cannot be called on primitive types.

Some useful readings are:

TL;DR

In Java there is not such a comparison operator: ===, but == or equals

A longer explanation

In weakly typed languages such as JavaScript you can use the strict comparison operator (===) because the language allows comparison between variables which have different types.

For example, in JavaScript, you won't get a compile error if you do this:

var x = 10;
var y = 'foo';
console.log(x == y)

And it is useful, when you want to compare variables which may hold values that are "equals" but may be of different types.

For example

var x = 10;
var y = '10';
console.log(x == y) // true
console.log(x === y) // false

In strongly typed languages such as Java, you don't need to use a strict comparison operator because the language already "handles" the type comparison.

For example:

int x = 10;
String y = "10";
System.out.println("10" == y); // true
System.out.println(x == y); // compile error : Incompatible operand types int and String

So, basically, in Java, there is no need for checking for strictness using === (a syntax error is reported).

In the first place, the compiler will complain when you compare values of different types and conversion cannot be performed.

In the previous example of Java code, if you want to make a comparison between x and y you could use equals:

int x = 10;
String y = "10";
System.out.println(y.equals(x)); // compile warning: Unlikely argument type for equals(): int seems to be unrelated to String

As a side note, notice the equals method cannot be called on primitive types.

Some useful readings are:

add info
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
Rollback to Revision 8
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
deleted 38 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
deleted 3 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
deleted 20 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
Add info
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
Add info
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
added 115 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
Leave just parent link
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
added 127 characters in body
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
Source Link
lealceldeiro
  • 15.1k
  • 7
  • 55
  • 85
Loading
lang-java

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