'Array initialization with ternary operator in Java

Why will Java let me initialize an array like this: int[] anotherArray = {1,2,3,4,5};

But won't accept this: int[] anArray = (arr.length > 0) ? {1,2,3,4,5}: {};

Image



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source