Prove that the interface for a primitive type is an empty array in Java


The getInterfaces() method is used to prove that the interface for a primitive type is an empty array. A program that demonstrates this is given as follows −

Example

 Live Demo

package Test;
import java.util.*;
public class Demo {
   public static void main(String[] args) {
      Class c = int.class;
      Class[] interfaces = c.getInterfaces();
      System.out.println("The Interface is: " + Arrays.asList(interfaces));
   }
}

Output

The Interface is: []


Now let us understand the above program.

The int.class is a reference to the Class object for the primitive type int. The interface for this is determined using the getInterfaces() method. This is an empty array as is obvious when it is displayed. A code snippet which demonstrates this is as follows −

Class c = int.class;
Class[] interfaces = c.getInterfaces();
System.out.println("The Interface is: " + Arrays.asList(interfaces));


Updated on: 25-Jun-2020

74 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements