Here you can find the source of classFor(Object obj)
Object
.
Parameter | Description |
---|---|
obj | the object whose class to retrieve |
obj
's class, or the class
public static Class<?> classFor(Object obj)
//package com.java2s; //License from project: Open Source License import java.util.prefs.Preferences; public class Main { /**//from w ww. java2 s .c om * Returns the class for the given <code>Object</code>. This handles * catching the <code>ClassNotFoundException</code> thrown by * {@link Class#forName(String)}. If the exception is caught the * {@link Preferences} class is returned. * * @param obj * the object whose class to retrieve * @return <code>obj</code>'s class, or the {@link Preferences} class */ public static Class<?> classFor(Object obj) { Class<?> c = null; try { c = Class.forName(obj.getClass().getCanonicalName()); } catch (ClassNotFoundException e) { e.printStackTrace(); c = Preferences.class; } return c; } }