Skip to content

Instantly share code, notes, and snippets.

@swegner
Created October 21, 2016 22:44
Show Gist options
  • Save swegner/8f80dee5f6901952d6a4ae946e61b142 to your computer and use it in GitHub Desktop.
Save swegner/8f80dee5f6901952d6a4ae946e61b142 to your computer and use it in GitHub Desktop.
Testing PipelineOptions builder syntax using self-referencing generics
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class GenericPipelineOptions {
public interface PipelineOptions<T extends PipelineOptions<T>> {}
public interface OptionsA<T extends OptionsA<T>> extends PipelineOptions<T> {
T setA1();
T setA2();
}
public interface OptionsB<T extends OptionsB<T>> extends PipelineOptions<T> {
T setB1();
T setB2();
}
public interface OptionsAB<T extends OptionsA<T> & OptionsB<T>> extends OptionsA<T>, OptionsB<T> {}
@Test
public void testBuilderSyntax() {
OptionsAB<?> opt = null;
opt
.setA1()
.setA2()
.setB1()
.setB2();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment