-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emissions
committed
Feb 15, 2024
1 parent
18b04b3
commit 5596af4
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package uk.ac.york.student.example; | ||
|
||
public class Generic<T> { | ||
/** | ||
* This is a generic method that takes in a generic type and returns it | ||
* @param t | ||
* @return | ||
*/ | ||
public T test(T t) { | ||
return t; | ||
} | ||
|
||
public <U> U test2(U u) { | ||
return u; | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package uk.ac.york.student.example; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter // at the top of the class, lombok will generate the getters for us for all fields | ||
public class Lombok { | ||
private final String name; | ||
@Setter // lombok will generate the setter for us specifically for this field | ||
private int age; | ||
|
||
public Lombok(String name, int age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
public void test() { | ||
System.out.println(getName()); // lombok creates the getters for us | ||
System.out.println(getAge()); | ||
|
||
setAge(20); // lombok creates the setters for us | ||
System.out.println(getAge()); | ||
} | ||
|
||
public void testUtility() { | ||
// Utility test = new Utility(); // error thrown here -- @UtilityClass creates a private constructor | ||
// ^^ code is commented out so the project can compile, remove the // if you want to see the error | ||
} | ||
|
||
public void methodNotCompleted() { | ||
// todo: this is an example todo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package uk.ac.york.student.example; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class Utility { | ||
public static void test() { | ||
System.out.println("Hello world!"); | ||
} | ||
} |