My IDE (IntelliJ) warns me about an unchecked conversion:
Unchecked overriding: return type requires unchecked conversion. Found 'com.company.Main.Cat', required 'T'
Nevertheless my code works as expected. Is there something I can do to prevent this warning or does my code have a "design" flaw?
The following MCVE reproduces the warning in public Cat copy()
for Cat
.
public static void main( String[] args )
{
Cat cat = new Cat( "Mimi" );
Cat copyCat = cat.copy();
}
public static class Cat extends Animal
{
public String name;
public Cat( final String name )
{
this.name = name;
}
@Override
public Cat copy() // Unchecked conversion warning
{
return new Cat( this.name );
}
}
public abstract static class Animal
{
abstract < T extends Animal > T copy();
}