Linked Questions
30 questions linked to/from Comparing Java enum members: == or equals()?
6
votes
1
answer
16k
views
The best way to compare enums [duplicate]
I have an enum, for example enum Color { Red, Brown }. I also have some variables of that type:
Color c1 = Brown, c2 = Red
What is best way to compare to a constant value:
if (c1 == Color.Brown) { ...
7
votes
5
answers
606
views
Enum equals() and == [duplicate]
enum Drill{
ATTENTION("Attention!"), AT_EASE("At Ease");
private String str;
private Drill(String str){
this.str = str;
}
public String ...
0
votes
1
answer
2k
views
are java enums singleton? [duplicate]
do java enums are singleton?
for example :
public enum State {
ACTIVE(0),
PENDING(1),
DELETED(2),
}
State s = State.ACTIVE;
State s2 = State.PENDING;
State s3 = State.PENDING;
is java create new ...
2
votes
1
answer
204
views
how to check equal for enum [duplicate]
I have Enum
public class TestResult {
MY_ENUM {
@Override
public String toString() {
return "Test1";
}
@Override
public boolean isTested() {
...
1
vote
0
answers
96
views
Which is the best way to compare enums in Java? Why I should use == and not .equals() method? [duplicate]
Which is the best way to compare enums in Java?
0
votes
0
answers
86
views
behaviour of '==' in case of enums in java [duplicate]
following snippet of code astonished me
public class enums
{
enum days
{
M,T,W,TH,F,S,SU;
}
public static void main(String []args)
{
days d1=days.M;
...
798
votes
27
answers
852k
views
What is the difference between == and equals() in Java?
I wanted to clarify if I understand this correctly:
== is a reference comparison, i.e. both objects point to the same memory location
.equals() evaluates to the comparison of values in the objects
64
votes
11
answers
79k
views
Javafx 2 click and double click
I would like to know if it was possible to detect the double-click in JavaFX 2 ? and how ?
I would like to make different event between a click and a double click.
Thanks
37
votes
7
answers
180k
views
How to compare Boolean?
Take this for example (excerpt from Java regex checker not working):
while(!checker) {
matcher = pattern.matcher(number);
if(matcher.find())
checker = true;
else
year++;
}
...
24
votes
6
answers
104k
views
Check if DAY_OF_WEEK is between Monday and Friday
I'm trying to create a method which is checking if "today" is between Monday and Friday. For this I get with this line 'int day = Calendar.DAY_OF_WEEK;' the actual day. After that I fill a ArrayList ...
15
votes
5
answers
10k
views
Thread safety in Singleton
I understand that double locking in Java is broken, so what are the best ways to make Singletons Thread Safe in Java? The first thing that springs to my mind is:
class Singleton{
private static ...
5
votes
7
answers
3k
views
Singleton in java
I just got to read the following code somewhere :
public class SingletonObjectDemo {
private static SingletonObjectDemo singletonObject;
// Note that the constructor is private
private ...
4
votes
5
answers
28k
views
How to check equals on enum value?
How can I check equality on a value of an enum? I tried the following, but it fails. WHy?
class enum Test {
LETTER("1A");
private String value;
public Test(String value) {
this....
9
votes
2
answers
16k
views
Filter by enum class property Kotlin
How do I filter by an enum class in kotlin? (just learning)
In the code below the enum class defined earlier in the file is PayStatus{PAID,UNPAID}.
fun nextRentDate(): LocalDate? {
return ...
6
votes
2
answers
1k
views
Why does comparing enums using == cause a PMD warning?
The following compares two enum values using ==:
MyEnum enum1 = blah(); // could return null
MyEnum enum2 = blahblah() // could return null
if (enum1 == enum2) {
// ...
}
But PMD gives a ...