Reflection-11-lombok 和反射 toString
2018年7月1日大约 1 分钟
Reflection
getClass()
Here is the jdk1.7 doc.
public Class[] getClasses()
The actual result type is Class
where |X| is the erasure of the static type of the expression on which getClass is called.
toString()
- Here is a ReflectionUtil.java helps you say goodbye to toString();
package com.ryo.util;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by houbinbin on 16/5/21.
*/
public class ReflectionUtil {
/**
* base toString() method;
* @param thisObj
* @return
*/
public static String toString(Object thisObj) {
Class clazz = thisObj.getClass();
String entityName = clazz.getSimpleName();
Field fields[] = clazz.getDeclaredFields();
StringBuilder stringBuilder = new StringBuilder(String.format("%s{", entityName));
for(int i = 0; i [lombok doc](https://projectlombok.org/features/index.html)
- add jar
```xml
org.projectlombok
lombok
1.16.8
- install plugin in idea.
IntelliJ IDEA->Prefercence->plugins
search for lombok, install and restart.
贡献者
binbin.hou