Are Generics applied at compile time or run time?

Generics is a concept in Java where you can enable a class, interface and, method, accept all (reference) types as parameters. In other words it is the concept which enables the users to choose the reference type that a method, constructor of a class accepts, dynamically. By defining a class as generic you are making it type-safe i.e. it can act up on any datatype.


 Live Demo

class Student<T>{
   T age;
   Student(T age){
      this.age = age;
   public void display() {
      System.out.println("Value of age: "+this.age);
public class GenericsExample {
   public static void main(String args[]) {
      Student<Float> std1 = new Student<Float>(25.5f);
      Student<String> std2 = new Student<String>("25");
      Student<Integer> std3 = new Student<Integer>(25);


Value of age: 25.5
Value of age: 25
Value of age: 25