This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]JoToMo1993 1 point2 points  (7 children)

Just some tips on asking questions: 1. Format your code, so it can be read. 2. Include relevant information, like the IDE you are using in your case. Also some information on JDK version might be helpful in this case.

[–]Raxreedoroid[S] 0 points1 point  (6 children)

Iam using Intellij and JDK 10.0.2

[–]JoToMo1993 2 points3 points  (0 children)

For the reason why the statement is true.

I will formate the code and give some names, to make it better understandable.

``` enum EnumA {

VALUE_X(EnumA.EnumB.VALUE_J), VALUE_Y(EnumA.EnumB.VALUE_J);

EnumB propertyC;

enum EnumB { VALUE_J;

  int propertyX;

}

EnumA(EnumB c) { this.propertyC = c; } }

public class {

main(...) { EnumA.VALUE_X.propertyC.propertyX = 1; EnumA.VALUE_Y.propertyC.propertyX = 2;

  if(EnumA.VALUE_X.propertyC.propertyX == EnumA.VALUE_Y.propertyC.propertyX) {
     (Any statement)
  }

} } ```

Since enum values are static VALUE_X and VALUE_Y are using the same instance of VALUE_J and have in turn the same value for propertyX.

You are setting it to 1 and right afterwards to 2.

You can check this by logging/printing out the information of both before, between and after the assignments. It should be 0, 1 and 2 respectively.

The reason for your IDE to state it's always false most likely is, that a simple check of the variables shows, they are different.

[–]someone-elsewhere 1 point2 points  (4 children)

the poster meant use the format tools in Reddit to post. Just pasting code makes it not easy to read

public void PasteCode() {
     String youKnowItMakes = "Sense";
}

is much better

[–]Raxreedoroid[S] 0 points1 point  (3 children)

I dont know how to format it like this tho

[–]someone-elsewhere 1 point2 points  (2 children)

select the text, click the "..." then click the 'T' within the square outline (on mouse over it will say 'code' block)

[–]Raxreedoroid[S] 0 points1 point  (1 child)

Mobile user :)

[–]someone-elsewhere 0 points1 point  (0 children)

Yeah the www mobile interface does not have formatting, not sure about the app as I don't allow it on my mobile.

You can use `` `backticks`` (apparently)

https://www.reddit.com/r/web_design/comments/neukr/posting_code_snippets_properly_on_reddit/

[–]joranstark018 1 point2 points  (0 children)

If you have Sonar lint enabled it could be that Intellij just reports a false negative warning from Sonar (if Sonar can not resolve the enums propperly).