Is there a way to avoid the unchecked class cast in this hierarchical Builder pattern?
public abstract class BaseBuilder <T, B extends BaseBuilder<T,B>> {
public B setB1(String b1) {
this.b1 = b1;
return (B) this; // can I make this unchecked cast go away?
}
abstract public T build();
String b1;
}
and no, the answer is not:
return B.class.cast(this);
and yes, I know I could use @SuppressWarnings