RFR: 7903727: Remove the reliance on String Templates feature [v5]

Nizar Benalla nbenalla at openjdk.org
Wed Jun 5 01:37:07 UTC 2024


On Tue, 4 Jun 2024 11:38:24 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Nizar Benalla has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Remove space, to not appear in the diff
>
> src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java line 134:
> 
>> 132:     }
>> 133:     void appendLines(String s, String... args) {
>> 134:         sb.appendLines(String.format(s, (Object []) args));
> 
> Why is this `Object[]` cast needed here?

Short answer is that I would get a warning

src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java:134: warning: non-varargs call of varargs method with inexact argument type for last parameter;
        sb.appendLines(String.format(s,  args));
                                         ^
  cast to Object for a varargs call
  cast to Object[] for a non-varargs call and to suppress this warning
1 warning

Without the cast, javac treats `args` as a simple argument of type `String []` while this is the signature for `String.format`

public static String format(String format,Object... args)

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/244#discussion_r1626812243


More information about the jextract-dev mailing list