Skip to content

Compilation error when trying to assign int to Serializable #1385

@mauromol

Description

@mauromol

Consider this Java class:

package testserializable;

import java.io.Serializable;

public class MyClass {

	private Serializable id;
	
	public Serializable getId() {
		return id;
	}
	
	public void setId(Serializable id) {
		this.id = id;
	}
}

and this Groovy class:

package testserializable

import groovy.transform.CompileStatic

@CompileStatic
class TestSerializable {
	void foo() {
		def c = new MyClass(id: -1)
	}
}

An error is shown in the editor:

Groovy:[Static type checking] - Cannot assign value of type int to variable of type java.io.Serializable

Same problem if I do:

def c = new MyClass()
c.id = -1

Fixed if I do: -1 as Integer.

This is a regression for sure, but I don't know when it started to appear.
Using Greclipse 4.7.0.v202208210205-e2112.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions