My class inherits from the parent class, which uses the common through grandparents. The same class also contains the inner class used for the builder. Since I am influencing a generic variable, I got a compilation warning.
Note: Child.java uses unchecked or unsafe operations.
Here is a simplified version of my project.
Other.java
public class Other
{}
Grandparent.java
public class GrandParent<T>
{
protected T t;
}
Parent.java
public class Parent<T> extends GrandParent
{}
Child.java
public class Child extends Parent<Other>
{
public static class Inner
{
public void iDoUnsafeStuff(Other other) {
Child child = new Child();
child.t = other;
}
}
}
Below is a more detailed output of compiling using -Xlint:unchecked.
Child.java:8: warning: [unchecked] unchecked assignment to variable t as member of raw type GrandParent
child.t = other;
What is the correct way in Java to use the generic type of grandparents?
In other words, how to make type Otherc iDoUnsafeStuff()according to the grandfather?
Please note that I want to understand what is wrong and not suppress the warning.