diff --git a/java/src/dev/andreijiroh/studentops/projects/helloGenerics.java b/java/src/dev/andreijiroh/studentops/projects/helloGenerics.java new file mode 100644 index 0000000..3a1efe4 --- /dev/null +++ b/java/src/dev/andreijiroh/studentops/projects/helloGenerics.java @@ -0,0 +1,37 @@ +package dev.andreijiroh.studentops.projects; + +public class helloGenerics { + public static void main(String[] args) { + class helloGen { + private T data; + + public void setValue(T dt) { + data = dt; + } + + public void showType() { + System.out.println("Type of T is " + data.getClass().getName()); + } + + public T getValue(){ + return data; + } + } + + helloGen name = new helloGen<>(); + name.setValue("Andrei Jiroh Halili"); + name.showType(); + + helloGen section = new helloGen<>(); + section.setValue("BSIT102B"); + section.showType(); + + helloGen course = new helloGen<>(); + course.setValue("BSIT"); + course.showType(); + + System.out.println("Name: " + name.getValue()); + System.out.println("Section: " + section.getValue()); + System.out.println("Course: " + course.getValue()); + } +}