mirror of
https://github.com/github/codeql.git
synced 2025-12-19 18:33:16 +01:00
These feature substituted types according to their declaring generic specialisation, with wildcards that reach top-level being converted to their upper or lower bound depending on usage context. This commit also includes an incidental fix such that constructors declare their return-type as unit, consistent with the Java extractor.
34 lines
673 B
Java
34 lines
673 B
Java
class Generic2<T> {
|
|
|
|
public Generic2(T init) { stored = init; }
|
|
|
|
private T stored;
|
|
|
|
T identity2(T param) { return identity(param); }
|
|
T identity(T param) { return param; }
|
|
T getter() { return stored; }
|
|
void setter(T param) { stored = param; }
|
|
|
|
}
|
|
|
|
public class Test {
|
|
|
|
public static void user() {
|
|
|
|
Generic2<String> invariant = new Generic2<String>("hello world");
|
|
invariant.identity("hello world");
|
|
invariant.identity2("hello world");
|
|
|
|
Generic2<? extends String> projectedOut = invariant;
|
|
projectedOut.getter();
|
|
|
|
Generic2<? super String> projectedIn = invariant;
|
|
projectedIn.setter("hi planet");
|
|
projectedIn.getter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|