RFR: JDK-8235621: Replace use of Function<?,Integer> with ToIntFunction

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue Dec 10 01:28:23 UTC 2019


Rémi,

While I understand the use of wildcards for parameters and return types, I don't think it makes sense to allow/use "? super Symbol" in this situation.  I'd prefer to keep it simple and just use ToIntFunction<Symbol>.

-- Jon


On 12/09/2019 05:20 PM, Remi Forax wrote:
> Hi Jonathan,
> for addExtraAttributes, the method should be
>
>    public void addExtraAttributes(ToIntFunction<? super Symbol> addExtraAttributes) {
>
> for the same reason a public method should take a List and not an ArrayList, so you can call it with
>    addExtraAttributes((Object o) -> 12);
> if the attribute is constant.
>
> If addExtraAttributes takes a ToIntFunction<? super Symbol>, you will have to use ToIntFunction<? super Symbol> everywhere.
>
> I should propose a new JEP to lock Dan Smith into a prison until JEP 300 [1] is delivered, because we will be able to get ride of most of those pesky wildcards (at least all the ones on functional interfaces) if that JEP is delivered.
>
> regards,
> Rémi
>
> [1] https://openjdk.java.net/jeps/300
>
> ----- Mail original -----
>> De: "jonathan gibbons" <jonathan.gibbons at oracle.com>
>> À: "compiler-dev" <compiler-dev at openjdk.java.net>
>> Envoyé: Mardi 10 Décembre 2019 01:38:44
>> Objet: RFR: JDK-8235621: Replace use of Function<?,Integer> with ToIntFunction
>> Following Rémi's suggestion[1], please review a trivial change to javac
>> to have it use ToIntFunction
>> instead of Function<..., Integer> in the recent patch for JDK-8234689 [2].
>>
>> Patch inline below. No change to the original test is necessary.
>>
>> JBS: https://bugs.openjdk.java.net/browse/JDK-8235621
>> [1]
>> https://mail.openjdk.java.net/pipermail/compiler-dev/2019-December/014043.html
>> [2] https://hg.openjdk.java.net/jdk/jdk/rev/17b0f051280f
>>
>> -- Jon
>>
>> diff -r 2aaa8bcb90a9 -r 1e000f399f3a
>> src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
>>
>> ---
>> a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
>> Mon Dec 09 15:28:46 2019 +0100
>> +++
>> b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
>> Mon Dec 09 16:12:42 2019 -0800
>> @@ -30,7 +30,7 @@
>>   import java.util.Map;
>>   import java.util.Set;
>>   import java.util.LinkedHashSet;
>> -import java.util.function.Function;
>> +import java.util.function.ToIntFunction;
>>
>>   import javax.tools.JavaFileManager;
>>   import javax.tools.FileObject;
>> @@ -114,7 +114,7 @@
>>        */
>>       public boolean multiModuleMode;
>>
>> -    private List<Function<Symbol, Integer>> extraAttributeHooks =
>> List.nil();
>> +    private List<ToIntFunction<Symbol>> extraAttributeHooks = List.nil();
>>
>>       /** The initial sizes of the data and constant pool buffers.
>>        *  Sizes are increased when buffers get full.
>> @@ -191,7 +191,7 @@
>>           }
>>       }
>>
>> -    public void addExtraAttributes(Function<Symbol, Integer>
>> addExtraAttributes) {
>> +    public void addExtraAttributes(ToIntFunction<Symbol>
>> addExtraAttributes) {
>>           extraAttributeHooks =
>> extraAttributeHooks.prepend(addExtraAttributes);
>>       }
>>
>> @@ -1669,7 +1669,7 @@
>>        */
>>       protected int writeExtraAttributes(Symbol sym) {
>>           int i = 0;
>> -        for (Function<Symbol, Integer> hook : extraAttributeHooks) {
>> +        for (ToIntFunction<Symbol> hook : extraAttributeHooks) {
>>               i += hook.apply(sym);
>>           }
>>            return i;



More information about the compiler-dev mailing list