groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paolo Di Tommaso <paolo.ditomm...@gmail.com>
Subject Re: Byte literal
Date Thu, 16 Jan 2020 12:47:11 GMT
For reference

https://issues.apache.org/jira/browse/GROOVY-9366


p

On Wed, Jan 15, 2020 at 11:37 PM Paolo Di Tommaso <paolo.ditommaso@gmail.com>
wrote:

> To summarize the current status
>
> First try:
>
> public @interface Version {
>     byte value();
> }
> class Foo {
>   @Version(0x01) String bar
> }
>
>
>       Error: Attribute 'value' should have type 'java.lang.Byte'; but
> found type 'int' in @Version
>
> Second try:
>
> public @interface Version {
>     byte value();
> }
> class Foo {
>   @Version(1 as byte) String bar
> }
>
> Expected '(byte) 1' to be an inline constant of type byte in @Version
>  at line: 6, column: 14
>
> Attribute 'value' should have type 'java.lang.Byte'; but found type
> 'java.lang.Object' in @Version
>  at line: -1, column: -1
>
>
> Third try:
>
>
> public @interface Version {
>     byte value();
> }
> class Foo {
>   public static final byte ONE = 0b01
>   @Version(ONE) String bar
> }
>
> Expected 'ONE' to be an inline constant of type byte not a field
> expression in @Version
>  at line: 7, column: 12
>
> Attribute 'value' should have type 'java.lang.Byte'; but found type
> 'java.lang.Object' in @Version
>  at line: -1, column: -1
>
>
>
> This is a very sad story.
>
>
> p
>
>
> On Wed, Jan 15, 2020 at 11:14 PM Simon Sadedin <ssadedin@gmail.com> wrote:
>
>> >I'm getting the following error:
>> >
>> > Error:Groovyc: Attribute 'value' should have type 'java.lang.Byte'; but
>> found type 'java.lang.Integer' in @Version
>>
>> I have a similar type of problem where I cannot find any way to invoke
>> Arrays.fill() for the byte version  - even with explicit workarounds that
>> should ensure a primitive byte is passed, for example:
>>
>>         def result = new byte[10][10]
>>         final Byte minusOne = -1
>>         for(int i=0; i<10; ++i) {
>>             Arrays.fill(result, 0, dim, minusOne.byteValue())
>>         }
>>
>> It happens with and without CompileStatic and results in:
>>
>> java.lang.ArrayStoreException: java.lang.Byte
>> at java.util.Arrays.fill(Arrays.java:3155)
>>
>> For these kind of cases  I'm left having to create little Java stub
>> workarounds to get it to call the right underlying Java API.
>>
>> Would be nice to have at least a way to work around this!
>>
>> Cheers,
>>
>> Simon
>>
>>
>>

Mime
View raw message