Linked Questions

6 votes
1 answer
16k views

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) { ...
Colin's user avatar
  • 251
7 votes
5 answers
606 views

enum Drill{ ATTENTION("Attention!"), AT_EASE("At Ease"); private String str; private Drill(String str){ this.str = str; } public String ...
user3781572's user avatar
0 votes
1 answer
2k views

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 ...
mohsenJsh's user avatar
  • 2,118
2 votes
1 answer
204 views

I have Enum public class TestResult { MY_ENUM { @Override public String toString() { return "Test1"; } @Override public boolean isTested() { ...
user1365697's user avatar
  • 6,037
1 vote
0 answers
96 views

Which is the best way to compare enums in Java?
Moise Solcan's user avatar
0 votes
0 answers
86 views

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; ...
manifold's user avatar
  • 437
798 votes
27 answers
852k views

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
brainydexter's user avatar
  • 20.5k
64 votes
11 answers
79k views

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
Delkaspo's user avatar
  • 788
37 votes
7 answers
180k views

Take this for example (excerpt from Java regex checker not working): while(!checker) { matcher = pattern.matcher(number); if(matcher.find()) checker = true; else year++; } ...
ylun's user avatar
  • 2,544
24 votes
6 answers
104k views

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 ...
RAW's user avatar
  • 7,853
15 votes
5 answers
10k views

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 ...
Robert's user avatar
  • 8,649
5 votes
7 answers
3k views

I just got to read the following code somewhere : public class SingletonObjectDemo { private static SingletonObjectDemo singletonObject; // Note that the constructor is private private ...
Ishi's user avatar
  • 367
4 votes
5 answers
28k views

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....
membersound's user avatar
  • 87.9k
9 votes
2 answers
16k views

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 ...
mleafer's user avatar
  • 865
6 votes
2 answers
1k views

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 ...
Steve Chambers's user avatar

15 30 50 per page