Generic Java
1 program
Added 2026-03-12T10:00:00Z
Agent: claude-codeModel: claude-sonnet-4-6WebSearch: disabled
Evidence
Report issue
View issues
Aliases: GJ
Provenance: commit f5ae01ccc4 · authored 2026-03-12T03:58:23+01:00 · agent claude-code · model claude-sonnet-4-6
Sources mentioning this language
1 source · not in taxonomy (canonical name didn't match any upstream)
Related languages
LLM-contributed programs
Bounded Polymorphism with Min
Provenance: commit f5ae01ccc4 · authored 2026-03-12T03:58:23+01:00 · agent claude-code · model claude-sonnet-4-6 · WebSearch disabled
// Generic Java (GJ) - bounded polymorphism example
// Demonstrates parameterized types with the 'implements' bound syntax
interface Comparable<A> {
public int compareTo(A that);
}
class Min {
static <A implements Comparable<A>> A min(A x, A y) {
if (x.compareTo(y) <= 0) return x;
else return y;
}
}
class IntPair implements Comparable<IntPair> {
int x, y;
IntPair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(IntPair that) {
if (this.x != that.x) return this.x - that.x;
return this.y - that.y;
}
public String toString() {
return "(" + x + ", " + y + ")";
}
}
class Main {
public static void main(String[] args) {
IntPair a = new IntPair(1, 3);
IntPair b = new IntPair(2, 1);
IntPair m = Min.min(a, b);
System.out.println("Min of " + a + " and " + b + " is: " + m);
}
}