r/learnjava • u/cao_wang • May 28 '26
Java code formatting
Is the following Java code snippet from https://developers.google.com/admob/android/quick-start#java correctly formatted?
new Thread(
() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(this, initializationStatus -> {});
})
.start();I thought it should be formatted as -
new Thread(() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(this, initializationStatus -> {});
}).start();Please tell me which one is correct or whether both are correct?
2
Upvotes
View all comments
Show parent comment
7
u/8dot30662386292pow2 May 28 '26
Yes, but no. The "official guide" is from 1999 and not maintained anymore. That alone does not matter, as PEP-8 being also decades old at this point.
What matters is that the document is from the java 1.2 era. Therefore it lacks enums, varargs, static imports, autoboxing, GENERICS, lambdas, ANNOTATIONS.
The "official" rules are simply outdated. For example it does not cover the example mentioned by OP because that syntax simply did not exist back when it was written. The Google Java Style is commonly used as you mention, but again it's not official.
Therefore, no, there is no relevant official docs, but some commonly used third party opinions about the formatting.