As you may already know, Kotlin (and many other programming languages) has a nice feature called trailing comma. This is a comma symbol after the last item of a series of elements.
But do you know that Java supports trailing commas too? The support is very limited but still worth noting.
You can use trailing commas in two cases:
- Array initialisers:
int[] answers = new int[]{
42,
7 * 6,
14 * 3,
21 * 2,
7 * 3 * 2, // trailing comma
};
- Enums:
enum Answer {
YES,
NO,
MAYBE,
FORTY_TWO, // trailing comma
}
Dream your code, code your dream.
Top comments (0)