hg: jdk7/tl/jdk: 6921740: Eliminate warnings from sun.io converters and allow compiling with JAVAC_MAX_WARNINGS=true

Rémi Forax forax at univ-mlv.fr
Tue Feb 2 13:30:41 UTC 2010

Le 02/02/2010 14:09, Ulf Zibis a écrit :
> Hi,
> in most cases you use the empty diamond operator '<>' on 
> instantiation, but not for SoftReference: "new 
> SoftReference<Charset>(cs)" in AbstractCharsetProvider.java
> Why?

SoftReference constructor is SoftReference(T), so there is two ways to 
infer the type argument.

With this code:
SoftReference<Charset> ref = new SoftReference<>(cs);
the type argument can be infered from the lhs of the assignation or
by the declared type of the parameter (here cs).

Knowing that the algorithm for infering the type argument changed and 
will change
(even if its in a backward compatible way), it seems to be a good rational
to only use diamond when the type can be only infered from the lhs type.
At least until, the JLS specifies the algorithm.

> I don't see a big advantage for casting to (Class<?>) against (Class) 
> for the cache of Converters.java.

Rules for Class<?> and Class are not the same.
Class should be only used when dealing with legacy code.

> -Ulf


More information about the core-libs-dev mailing list