Is it fine to write following?
Set<Integer> integs = new HashSet<>();
Inside <>, is it fine to leave it as empty?
As from Java 7, the compiler will infer the data type of the hash set without the need to write it twice.
Note though that there are some scenarios where the compiler might fail to infer the type, so you could get compilation errors for more complex scenarios.
More of that here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With