public class MetaUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
MetaUtils.Dumpty |
Modifier and Type | Method and Description |
---|---|
static Map<String,Field> |
getDeepDeclaredFields(Class<?> c) |
static int |
getDistance(Class<?> a,
Class<?> b) |
static Field |
getField(Class<?> c,
String field)
Return an instance of of the Java Field class corresponding to the passed in field name.
|
static String |
getLogMessage(String methodName,
Object[] args)
Format a nice looking method signature for logging output
|
static String |
getLogMessage(String methodName,
Object[] args,
int argCharLen) |
static boolean |
isLogicalPrimitive(Class c) |
static boolean |
isPrimitive(Class c) |
static Object |
newInstance(Class c)
C language malloc() for Java
|
static void |
setUseUnsafe(boolean state)
Globally turn on (or off) the 'unsafe' option of Class construction.
|
public static void setUseUnsafe(boolean state)
state
- boolean true = on, false = off.public static Field getField(Class<?> c, String field)
c
- class containing the field / field namefield
- String name of a field on the class.public static Map<String,Field> getDeepDeclaredFields(Class<?> c)
c
- Class instancepublic static int getDistance(Class<?> a, Class<?> b)
a
- Class source classb
- Class target classpublic static boolean isPrimitive(Class c)
c
- Class to testpublic static boolean isLogicalPrimitive(Class c)
c
- Class to testpublic static Object newInstance(Class c)
C language malloc() for Java
Create a new instance of the passed in Class. This method will make a valiant effort to instantiate the passed in Class, including calling all of its constructors until successful. The order they are tried are public with the fewest arguments first to private with the most arguments. If, after exhausting all constructors, then it will attempt using the 'unsafe allocate' from Sun. This step is optional - by default it will use this if on a Sun (Oracle) JVM unless MetaUtil.setUseUnsafe(false) is called.
This method will handle common interfaces, such as Collection, Map, etc. which commonly show up in parameterized types. Any other interface passed to this method will cause a JsonIoException to be thrown.
To improve performance, when called a 2nd time for the same Class, the constructor that was successfully used to construct the instance will be retrieved from an internal cache.
c
- Class to instantiateJsonIoException
- if it cannot instantiate the passed in class.public static String getLogMessage(String methodName, Object[] args)
Copyright © 2024. All rights reserved.