Skip to content

Commit

Permalink
added some examples to look through
Browse files Browse the repository at this point in the history
  • Loading branch information
Emissions committed Feb 15, 2024
1 parent 18b04b3 commit 5596af4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/uk/ac/york/student/example/Generic.java
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
}
}
33 changes: 33 additions & 0 deletions src/main/java/uk/ac/york/student/example/Lombok.java
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
}
}
10 changes: 10 additions & 0 deletions src/main/java/uk/ac/york/student/example/Utility.java
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!");
}
}

0 comments on commit 5596af4

Please sign in to comment.