I to know if it is possible to have an if statement in a method that will check the type of the generic used.
Not in general, no - because of type erasure. Basically the type of T
isn't known at execution time.
You could use:
if (point instanceof Point3D)
but that's not quite the same as checking whether T
itself is Point3D
. It's probably a better idea though:
public void processPoints(Point point) {
process(point.x);
process(point.y);
if (point instanceof Point3D) {
Point3D point3d = (Point3D) point;
process(point3d.z);
}
}