REFLECTION / CATATAN</>↗Reflection12 Des 2010
The Class.getComponentType() method call returns the Class representing the component type of array. If this class does not represent an array class this method returns null reference instead. package org.kodejava.lang.reflect; public class ComponentTypeDemo { public static void main(String[] args) { String[] words = {"and", "the"}; int[][] matrix = {{1, 1}, {2, 1}}; Double number = […]
REFLECTION / CATATAN</>↗Reflection12 Des 2010
For checking if a class object is representing an array class we can use the isArray() method call of the Class object. This method returns true if the checked object represents an array class and false otherwise. package org.kodejava.lang.reflect; public class IsArrayDemo { public static void main(String[] args) { int[][] matrix = {{1, 1}, {2, […]
REFLECTION / CATATAN</>↗Reflection11 Des 2010
Java reflection also dealing with inheritance concepts. You can get the direct interfaces and direct super class of a class by using method getInterfaces() and getSuperclass() of java.lang.Class object. getInterfaces() will returns an array of Class objects that represent the direct super interfaces of the target Class object. getSuperclass() will returns the Class object representing […]
REFLECTION / CATATAN</>↗Reflection11 Des 2010
You can use the isInterface() method call of the java.lang.Class to identify if a class objects represent an interface type. package org.kodejava.lang.reflect; import java.io.Serializable; public class IsInterfaceDemo { public static void main(String[] args) { IsInterfaceDemo.get(Serializable.class); IsInterfaceDemo.get(Long.class); } private static void get(Class<?> clazz) { if (clazz.isInterface()) { System.out.println(clazz.getName() + " is an interface type."); } else […]
REFLECTION / CATATAN</>↗Reflection11 Des 2010
Java uses class objects to represent all eight primitive types. A class object that represents a primitive type can be identified using the isPrimitive() method call. void is not a type in Java, but the isPrimitive() method returns true for void.class. package org.kodejava.lang.reflect; public class IsPrimitiveDemo { public static void main(String[] args) { IsPrimitiveDemo.get(int.class); IsPrimitiveDemo.get(String.class); […]
REFLECTION / CATATAN</>↗Reflection11 Des 2010
package org.kodejava.lang.reflect; import java.util.Date; public class ClassNameDemo { public static void main(String[] args) { Date date = new Date(); // Gets the Class of the date instance. Class<?> clazz = date.getClass(); // Gets the name of the class. String name = clazz.getName(); System.out.println("Class name : " + name); // Gets the canonical name of the […]