Post

🌒 Eclipse Java IDE
🌒 Eclipse Java IDE@EclipseJavaIDE·
You seem to like String puzzles. What will be the output of this program?
🌒 Eclipse Java IDE tweet media
English
70
47
215
0
Charles Oliver Nutter
Charles Oliver Nutter@headius·
@EclipseJavaIDE @java Unsure if toString on a String is required to return same object. Alters the outcome if it could, say, return a stack-allocated value instead...
Richfield, MN 🇺🇸 English
0
0
0
0
gorlok 🧉🧙‍♂️
@EclipseJavaIDE I think it throws a NPE. "ABC".toString() returns the same value. "ABC"=="ABC" is true, because String cache. b is true. So... NullPointerException on Y.equals(...) (must be Y == null to be safe) if B = false, the short circuit logic would prevented NPE.
English
3
0
29
0
Reinhard Prehofer
Reinhard Prehofer@pre4711·
@EclipseJavaIDE @jSparrowpicks typical sample of how NOT to write Java programs and produce code smells and decrease readability within a few lines. Totally irrelevant what the output of the program would be, the output of the programmer is major reason to rethink further usability ...
English
0
0
1
0
Igor Dëmin
Igor Dëmin@idemin1·
@EclipseJavaIDE Depends on Java version, Java < 7 → false, Java >= 7 → NPE. Also your variables naming doesn't correspond to Eclipse Coding Conventions...
English
0
0
1
0
Giovanni
Giovanni@giovanni_n4·
@EclipseJavaIDE From Object.equals() java docs: "For any non-null reference value x, x.equals(null) should return false." and since Y is null ... NPE exception is thrown. Would have been evaluated to false if Y was initialized.
English
0
0
0
0
Jose M. Tuñas
Jose M. Tuñas@jmtr2002·
@EclipseJavaIDE False. toString returns a new String instance. The == is comparing references of X and "ABC".toString(). The NPE never is throwed.
English
0
0
0
0
شیئر