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.
 
![Cover image for [Tiny] Trailing commas in Java](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsivwy194xrh8xqpkerd1.jpg) 
              
 
    
Top comments (0)