AdvancedExpressionFolding icon indicating copy to clipboard operation
AdvancedExpressionFolding copied to clipboard

Improve readability of use-site variance generic expressions for contravariance and covariance

Open steveash opened this issue 9 years ago • 1 comments

Java's lack of declaration site expression of co/contra-variance dooms us to riddling our use-site generic code with verbose variance expressions that eat up many more characters than they are worth:

Map<String, ? extends Foo<? extends Bar>> myMap = new HashMap<>();

Perhaps a new feature of the Advanced Expression Folding plugin could be to optionally fold these long expressions into just a + or - to indicate covariance or contravariance. The leading plus or minus syntax would follow Scala's use of declaring generic parameter variance:

Map<String, +Foo<+Bar>> myMap = new HashMap<>

steveash avatar Jan 08 '17 16:01 steveash

How about var myMap = new HashMap<String, ? extends Foo<? extends Bar>>()

cheptsov avatar Jan 09 '17 11:01 cheptsov