문제

I'm wondering if there are any known performance differences in terms of the Java 7 diamond operator versus the language construct for previous versions of Java.

Basically, is it faster to use this:

List<String> myList = new ArrayList<>()
Map<String, Integer> myMap = new HashMap<>()

or to use this:

List<String> myList = new ArrayList<String>() 
Map<String, Integer> myMap = new HashMap<String, Integer>()

Are they the same speed?

도움이 되었습니까?

해결책

The generated bytecode is the same. The new diamond operator is purely implemented to save programmers from having to redundantly specify the type twice.

다른 팁

Negative. Due to type erasure, the diamond operator (and generics in general) have the same run-time performance as they always have (e.g. at run-time Collections just hold Object(s)).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top