Java Preference classFor(Object obj)

Here you can find the source of classFor(Object obj)

Description

Returns the class for the given Object.

License

Open Source License

Parameter

Parameter Description
obj the object whose class to retrieve

Return

obj's class, or the class

Declaration

public static Class<?> classFor(Object obj) 

Method Source Code


//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;
    }
}

Related

  1. backingStoreAvailable(Preferences prefs)
  2. cambiarIdioma(String lang, String country)
  3. clearPreference(Object context)
  4. count(Preferences preferences, String preferenceName)
  5. createNode(String path)
  6. hasEnv(String key, String value)