Naming conventions for constants in Java [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
When a constant variable ends with a number, do you need to put an underscore in between the number and the rest of the variable?
I haven't found a Java naming convention for this case.
For example YELLOW3 or YELLOW_3

Related

Best way to write Java 8 map statement that returns constant value [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have the following statement. The map always returned "Closed". But I think this statement s -> "CLOSED" could be rewritten using a better style.
Is there any better way to represent this?
String status = myOptional.map(s -> "CLOSED").orElse("OPEN");
Just use a ternary operatory to check for its presence :
String status = myOptional.isPresent() ? "CLOSED" : "OPEN";

Why can't the compiler warn against this programming error? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If I write the following code:
int a = 5;
if (a == 1 || a == 1) {
// do something
}
Why can't the compiler point out that the second part of the if statement is unnecessary, or warn that the programmer has likely made a mistake?
The compiler does not do it. But the IDE might detect the underlying problem. For example:

Why String method substring() is not in camelCase in Java? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
As per Java's standard we should follow CamelCase. But why String's method substring() is not in camelCase ? Is it for any specific reason or just an mistake from the initial days ?
I'd say because substring is one physical word.
camelCase is used to separate words, substring is not to be intended as Sub String but as Substring... so the convention is respected.

Why is there no function Stream.flatMap()? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Why is there no function Stream.flatMap() (without any parameters) to flatten a Stream<Stream<T>>?
It would simply be implemented as Stream.flatMap(o -> o).
In my opinion, this is by far the most common use of flatMap(Function mapper).
I would imagine because it's trivial to use
import static java.util.function.Function.identity;
...
streamOfStreams.flatMap(identity())

Java 7 Underscore Numeric literals [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Why Java 7 include feature of underscore numeric literals why not comma numeric literals?
The "," operator already has meaning, so existing code would change meaning:
// Is this 3 values or 2?
int[] values = { 123,456, 789 };

Categories

Resources