Skip to content

Commit

Permalink
added another method for an example
Browse files Browse the repository at this point in the history
  • Loading branch information
Emissions committed Feb 15, 2024
1 parent 5596af4 commit c58b63e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/uk/ac/york/student/example/Generic.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ public <U> U test2(U u) {
return u;
}

public <U extends String> U test3(U u) {
return (U) u.toUpperCase();
}

public static void testGeneric() {
Generic<String> generic = new Generic<>();
System.out.println(generic.test("Hello world!"));

Generic<Integer> generic2 = new Generic<>();
System.out.println(generic2.test(5)); // requires integer input
System.out.println(generic2.test2("hi")); // can be any input as the generic is defined on the method
System.out.println(generic2.test3("hi")); // requires string input
}
}

0 comments on commit c58b63e

Please sign in to comment.